0.0.1 • Published 7 years ago

little-di v0.0.1

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
7 years ago

Little DI

A very simple implementation of dependency injection concept for both frontend and backend in ES6.

Usage

const classesConfig = [
    {
        clazz: Engine,
        scope: 'prototype'
    },
    {
        clazz: Car,
        dependencies: [Engine],
        scope: 'prototype'
    },
    {
        clazz: Manufacture
    }
];
const container = new Container(classesConfig);

container.getClass('Engine');

API

Container class

ConstructorDescription
Container(config:ClassesConfig)Creates an container for all registered classes instances management. One application should only have one container.
MethodsDescription
getClass()Return Value: Class<T> - Fetches the scoped instance of the class.

ClassesConfig object specification

PropertiesDescription
clazzType: Class<T> - The instances of which to be managed.
dependenciesType: [Class<T>, <...>] - An array of dependent classes.
scopeType: string - the scope of the class instance. Available scopes are: SCOPE_SINGLETON and SCOPE_PROTOTYPE. Defaults to SCOPE_SINGLETON.