0.0.7 • Published 4 years ago

@random-di/v1-loader v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Build Status npm version Coverage Status Lightweight GitHub issues GitHub license

@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')