1.0.1 • Published 5 years ago

macro-injector v1.0.1

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

super-injector

a dependency injection library

Sample Code

// Simple Example
let MacroInjector = require("macro-injector");
let macroInjector = new MacroInjector();

macroInjector.addDependency("User",class{
    constructor(name,age){
        this.name = name;
        this.age = age;
    }

    log(){
        console.log(`${this.name} is ${this.age} years old!`)
    }
})

class UserService{
    setUser(name,age){
        this.user = new this.injections.User(name,age);
    }

    render(){
        this.user.log();
    }
}

let injectedUserService = macroInjector.inject(UserService,"User");
injectedUserService.setUser("The Creator of Super-Injector",19)
injectedUserService.render();

console.log(macroInjector.dependencies())

Removing Dependency

macroInjector.removeDependency("User");

Middleware

macroInjector.applyMiddleware("User",function(){
    console.log("Before Injecting User");
})

Error Event

let macroInjector = new MacroInjector();
macroInjector.on("error",message=>{
    console.log(message);
})
macroInjector.addDependency("User","User String can't be injected");