@forgeframework/di
v0.3.0
Published
Provides a lightweight, decorator-based dependency injection container for the Forge Framework.
Maintainers
Readme
@forgeframework/di
Provides a lightweight, decorator-based dependency injection container for the Forge Framework.
Part of the Forge Framework — a TypeScript framework for backend microservices and web applications.
Installation
npm install @forgeframework/diUsage
import { ForgeContainer, Injectable, Inject, Scope } from '@forgeframework/di';
@Injectable({ scope: Scope.SINGLETON })
class UserRepository {
findById(id: string) { /* ... */ }
}
@Injectable()
class UserService {
constructor(@Inject(UserRepository) private repo: UserRepository) {}
async getUser(id: string) {
return this.repo.findById(id);
}
}
const container = new ForgeContainer();
container.register(UserRepository, { useClass: UserRepository, scope: Scope.SINGLETON });
container.register(UserService, { useClass: UserService });
const userService = container.resolve(UserService);Documentation
Full API reference and guides: https://carbonforge.io/framework/docs/core/di
(Documentation site launching soon.)
License
MIT © Carbon Forge
