js-service-container
v0.0.1
Published
A simple and minimalistic service container for JavaScript and TypeScript.
Downloads
6
Maintainers
Readme
JavaScript Container
A simple and minimalistic and service container for JavaScript and TypeScript.
Usage
Start with building the container:
import {ContainerBuilder, SingletonService} from 'js-service-container';
const builder = new ContainerBuilder()
builder.singleton('class-a', container => {
return new ClassA()
})
builder.singleton('class-b', container => {
return new ClassB(container.get('class-a'))
})
builder.factory('class-c', container => {
return new ClassC(container.get('class-a'), container.get('class-b'))
})
const container = builder.build()
Next use the container to load the services. All services are singletons inside the container:
const classA = container.get('class-a')
const classB = container.get('class-b')
const classC = container.get('class-c')