@mudah-cli/container
v0.9.4
Published
High-performance IoC service container with constructor auto-injection.
Maintainers
Readme
@mudah-cli/container
High-performance IoC service container with constructor auto-injection.
Part of Mudah — an ergonomic, animation-rich CLI framework. This package has no Mudah dependencies, so you can use it in any TypeScript project.
Install
npm install @mudah-cli/containerUsage
import { Container } from '@mudah-cli/container';
class Database {
connect(): void {
// …
}
}
const container = new Container();
container.singleton(Database, Database); // or .bind(...) for a fresh instance each time
const db = container.make(Database);
db.connect();Bindings can be singletons, factories (sync or async), values, tagged, and contextual.
Decorate classes with @inject / @singleton for auto-injection, or resolve a whole provider
module with loadProvidersFrom.
