ts-simple-ioc
v1.0.6
Published
Simple TypeScript based IoC framework
Downloads
3
Maintainers
Readme
ts-simple-ioc
A simple IoC container for TypeScript, strongly influenced by Microsoft.Extensions.DependencyInjection.
Features
- Simple service registration & resolution
- Type safe service resolution
- No package dependencies
- No requirement on services to know about the IoC framework, e.g. no decorators
- Singleton & transient lifetime support
- Constructor dependency injection
- Property dependency injection
Getting started
Installation
npm install --save ts-simple-ioc
Registering and resolving services
import { Container } from "ts-simple-ioc";
class ExampleService {
constructor(public dependency: ExampleDependency) {}
}
class ExampleDependency {}
const container = new Container()
.addTransient(ExampleService, (resolve) => new ExampleService(resolve(ExampleDependency)))
.addSingleton(ExampleDependency, () => new ExampleDependency())
.beginResolution();
const service = container.resolve(ExampleService);
Roadmap
- v1.1.0
- Scoped lifetime support
- v1.2.0
- Circular dependency detection