Skip to content

zhenyanghua/little-di

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

ClassesConfig object specification

Properties Description
clazz Type: Class<T> - The instances of which to be managed.
dependencies Type: [Class<T>, <...>] - An array of dependent classes.
scope Type: string - the scope of the class instance. Available scopes are: SCOPE_SINGLETON and SCOPE_PROTOTYPE. Defaults to SCOPE_SINGLETON.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy