midge
Mini Injector
Install
npm install --save midge
Usage
const Midge = ; const cache = a: 123 b: 321; const factories = { return a + b; } { return b + c; }; // Create injector instanceconst injector = ; // Get resultslet a = injector;let b = injector;let c = injector;let d = injector; to;to;to;to; // Injecting into functionsinjector; // Injecting into constructorsinjector;
API
Injector methods
injector.get(name)
Returns instance(s) from cache or creates it/them by executing the injector factory
.
name
- A string or an array of strings with service-names.
injector.invoke(fn, [self], [locals])
Injects the given function while executing it with apply
.
fn
- Function to inject.self
- Object which will be bound tofn
asthis
.locals
- Optional object containing values, which will be used before before cache and factory.
injector.instantiate(ctor, [locals])
Injects the given constructor while instantiating it with new
ctor
- Constructor to inject.locals
- Optional object containing values, which will be used before before cache and factory.
Author
Twitter: @platdesign