Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including winter with all npm packages installed. Try it out:

var winter = require("winter")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

winter v1.0.3

Dependency injection that doesn't require you to change your code

Winter

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.
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free