0.3.0 • Published 4 years ago

@random-di/container v0.3.0

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

Build Status npm version Coverage Status Lightweight GitHub issues GitHub license

In software engineering, dependency injection is a technique in which an object receives other objects that it depends on. These other objects are called dependencies. Source Wikipedia

@random-di/container helps you register your applications dependencies by providing a dependency injection container.

Installation

npm i --save @random-di/container
yarn add @random-di/container

Usage

import {createContainerBuilder, LifeCycle} from '@random-di/container'

// Declare some services
class ServiceA {
}

class ServiceB {
    constructor(serviceA: ServiceA) {}
}

// Construct the container using a container builder
const builder = createContainerBuilder()
    .addFactory('serviceA', () => new ServiceA(), LifeCycle.Singleton)
    .addFactory(
        'serviceB', 
        provider => new ServiceB(provider.get<ServiceA>('serviceB')), 
        LifeCycle.Transient
    )

// Build the container
const container = builder.build()

// Retrieve the services
const serviceA = container.get<ServiceA>('serviceA')
const serviceB = container.get<ServiceB>('serviceB')

Docs

https://botflux.github.io/random-di

1.0.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago