1.0.2 • Published 10 months ago

ap-simple-di v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Ap Simple DI

npm version

A simple dependency injection system for TypeScript and Bun.

Installation

bun install ap-simple-di

Usage

import { Injectable, Inject } from 'ap-simple-di';

@Injectable()
class ServiceA {
  doSomething() {
    console.log('Service A is doing something');
  }
}

class ServiceB {
  @Inject(ServiceA) private serviceA!: ServiceA;

  doSomethingElse() {
    this.serviceA.doSomething();
    console.log('Service B is doing something else');
  }
}

// Usage
const serviceB = new ServiceB();
serviceB.doSomethingElse();

API

@Injectable()

Class decorator to register a class as injectable.

@Inject(key)

Property decorator to inject a dependency.

Container

The dependency injection container class.

License

MIT

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago