A lightweight dependency injection library for Node.js and TypeScript with decorators.
npm install @injets/core @injets/decorators
import { Container, Provider, Inject, mount } from '@injets/decorators';
@Provider()
class Provider1 {
method() {
console.log('Provider1 method');
}
}
@Provider()
class Provider2 {
@Inject()
provider1!: Provider1;
method() {
console.log('Provider2 method', this.provider1);
}
}
@Module({
providers: [Provider1, Provider2],
})
class MyApp {}
const app = mount(MyApp)
app.resolve(Provider2).method(); // Provider2 method Provider1 {}
Marks a class as a module (container)
Marks a class as a provider
Injects a provider into a property or constructor parameter
Options for the container.
interface ContainerOptions {
isGlobal?: boolean;
imports?: Class[];
providers?: Array<Class | Provider>;
exports?: Token[];
}
- @injets/functional - Support for functional programming in JavaScript and TypeScript.
- @injets/core - A lightweight dependency injection library for Node.js and TypeScript.