injectinto
v1.6.0
Published
Register and request components. Dependency injection for nodejs.
Downloads
7
Readme
Dependency Injection
config.coffee
inject = require 'pminject'
inject.bind templaterenderer: require 'nun'
inject.bind contenttypes: [
require './contenttypes/text'
require './contenttypes/image'
]
cms.coffee
inject = require 'pminject'
contenttypes = inject.many 'contenttypes'
templaterenderer = inject.one 'templaterenderer'
for contenttype in contenttypes
templaterenderer.render contenttype
What is the problem?
I'd like to build systems that can easily be extended, enhanced, or replaced.
How injectinto solves this problem
- Extension points are defined through strings, for example 'templateengine'
- In configuration these extension points are bound to actual objects
- A module asks for an object via it's string, for example 'templateengine'
- Some modules can expect an array of objects
Goals
- Simple
- Work with async
- Allow multiple registrations