Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 

Winter

This project is complete, no longer maintained and part of my source code "attic". Feel free to use it though, it works great!

Winter can do dependency injection without being intrusive on your existing code.

// hello.js
module.exports = function(){
    this.message = "Hello";
};
// main.js
module.exports = function(logger, hello){
    logger.info(hello.message);
};
// index.js
var Winter = require('winter');
var winter = new Winter();

winter.register('logger', new Winter.LoggerProvider());

winter.registerModules(require, {
    'main': './main',
    'hello': './hello'
});

winter.link().done();

This will output

[2014-04-06 16:06:09.104] [INFO] main - Hello

For static values like the above "Hello" string, it is better to use Winter.ValueProvider.

Additionally

  • You can create custom providers like LoggerProvider, check out the sources; it's easy.
  • Winter works with q promises; providers can freely return promises instead of instances directly.
  • Registering a provider more than once on the same name will overwrite the previous provider for that name.
  • Winter's link should only be called once, and all providers should be registered before calling link.
  • Cyclic and missing dependencies cause link's promise to fail, with information on whats wrong or missing.

About

Non-intrusive custom NodeJS dependency injection

Resources

Releases

No releases published

Packages

No packages published