A tiny, but powerful dependency injection container for your Node.js apps
- manual registering of factory fuctions and classes
- scanning directories for factory functions and classes to instantiate
- setting values and getting values
- injecting dependencies (duh)
const wireApp = ;;
The API is fluent. All functions, except
get() can be chained.
Constructs a new app and returns it.
; // prints `myApp`
All other functions mentioned below are part of the 'app' API.
register(fn) function will
- Invoke the
fnparameter and inject its dependencies
- register it in the application context, under the function name.
fn function should be a factory function OR a class, and must have a name.
The order you invoke the register functions does not matter. Wire-app will figure out dependency order.
register(fn) function returns the
app to provide a fluent API.
Scans recursively am absolute or relative directory for exposed factory methods and/or classes.
It will register them, similar to the
app.scan(scanPath) function returns the app to provide a fluent API.
Stores a value, under a certain key, in the application context
The value can be of any type. No dependency injection will occur
app.set(key, value) function returns the app to provide a fluent API.
Returns the value (or component) registered under the requested key.
app is an EventEmitter and will emit a few events
This event is emitted when the whole application was wired successfully.
It emits the
app as its first parameter
Will be emitted when something went wrong during the wiring phase.
The idea of the API comes from Dieter Luypaert.