@random-di/v1-loader
v0.0.7
Published
A @random-di/container service loader for @botflx/dependency-injection-container container
Downloads
3
Maintainers
Readme
@random-di/v1-loader
An adapter from @botflx/dependency-injection-container
to @random-di/container
.
Installation
npm i --save @random-di/v1-loader
yarn add @random-di/v1-loader
Usage
import {createServiceContainer} from '@botflx/dependency-injection-container'
import {createContainerBuilder, SyncServiceProviderInterface} from '@random-di/container'
import {v1Loader} from '@random-di/v1-loader'
class ServiceA {
public hello: string
constructor(provider: SyncServiceProviderInterface) {
this.hello = provider.get<string>('hello')
}
}
const v1Container = createServiceContainer()
.addFactory('hello', () => 'world')
.add('ServiceA', ServiceA)
const v2Container = createContainerBuilder({
loaders: [v1Loader(v1Container)]
}).build()
const hello = v2Container.get<string>('hello')
const serviceA = v2Container.get<ServiceA>('ServiceA')