@blixis-io/di
v0.1.3
Published
A small, readable dependency injection container — @Injectable, @Inject, tokens, providers, singleton/transient scopes.
Maintainers
Readme
@blixis-io/di
A small, readable dependency injection container — @Injectable, @Inject, tokens, providers, singleton/transient scopes.
npm install @blixis-io/diimport { Container, Injectable } from "@blixis-io/di";
@Injectable()
class Database {}
@Injectable()
class UserRepository {
constructor(public db: Database) {}
}
const container = new Container();
container.register(Database);
container.register(UserRepository);
const repo = await container.resolve(UserRepository);
repo.db; // a Database instance, built automaticallyResolves a graph of classes from their constructor parameter types, using nothing but a class decorator and TypeScript's own emitDecoratorMetadata output — no reflect-metadata call you have to make yourself, no manual registration of "what implements what" beyond registering the provider itself.
Part of Blixis Framework — full docs: Dependency Injection · API reference.
