How to use the di.Injector function in di

To help you get started, we’ve selected a few di examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github swagger-api / swagger-editor / node_modules / karma / lib / server.js View on Github external
socketServer: ['factory', createSocketIoServer],
    executor: ['type', Executor],
    // TODO(vojta): remove
    customFileHandlers: ['value', []],
    // TODO(vojta): remove, once karma-dart does not rely on it
    customScriptTypes: ['value', []],
    reporter: ['factory', reporter.createReporters],
    capturedBrowsers: ['type', BrowserCollection],
    args: ['value', {}],
    timer: ['value', {setTimeout: setTimeout, clearTimeout: clearTimeout}]
  }];

  // load the plugins
  modules = modules.concat(plugin.resolve(config.plugins));

  var injector = new di.Injector(modules);

  injector.invoke(start);
};
github jstty / hyper.io / lib / manager.service.js View on Github external
// add all _resources to list for DI
  resources = this._resources.getAllInstances();
  for (rKey in resources) {
    module[rKey] = ['value', resources[rKey]];
  }

  // add all service.resources to list for DI
  if (service) {
    resources = service.resources.getAllInstances();
    for (rKey in resources) {
      module[rKey] = ['value', resources[rKey]];
    }
  }

  // creates injector
  var injector = (new di.Injector([module]));

  // run function
  if (func) {
    if (parent) {
      return injector.invoke(func, parent);
    }
    else {
      return injector.invoke(func);
    }
  }
  else {
    if (parent) {
      if (parent.module.toString().indexOf('function') === 0) {
        var InjectedWrapper = function () {
          return injector.invoke(parent.module, this);
        };
github cameronmaske / skipper / client / node_modules / karma / lib / server.js View on Github external
socketServer: ['factory', createSocketIoServer],
    executor: ['type', Executor],
    // TODO(vojta): remove
    customFileHandlers: ['value', []],
    // TODO(vojta): remove, once karma-dart does not rely on it
    customScriptTypes: ['value', []],
    reporter: ['factory', reporter.createReporters],
    capturedBrowsers: ['type', BrowserCollection],
    args: ['value', {}],
    timer: ['value', {setTimeout: setTimeout, clearTimeout: clearTimeout}]
  }];

  // load the plugins
  modules = modules.concat(plugin.resolve(config.plugins));

  var injector = new di.Injector(modules);

  injector.invoke(start);
};
github RackHD / on-dhcp-proxy / index.js View on Github external
// Copyright 2015, EMC, Inc.

"use strict";

var di = require('di'),
    _ = require('lodash'),
    core = require('on-core')(di),
    injector = new di.Injector(
        _.flatten([
            core.injectables,
            core.helper.requireGlob(__dirname + '/lib/**/*.js')
        ])
    ),
    core = injector.get('Services.Core'),
    configuration = injector.get('Services.Configuration'),
    Logger = injector.get('Logger'),
    logger = Logger.initialize('Dhcp'),
    Server = injector.get('DHCP.Proxy.Server');

core.start()
.then(function() {
    Server.create(
        configuration.get('dhcpProxyBindPort', 4011),
        {
github angular / templating / test / view.spec.js View on Github external
it('should remove the watchGroup', ()=>{
      var root = new RootView($('<div></div>')[0], new Injector());
      spyOn(root.watchGrp, 'remove').and.callThrough();
      root.destroy();
      expect(root.watchGrp.remove).not.toHaveBeenCalled();

      var childView = new View(root, $('<div></div>')[0], new Injector());
      spyOn(childView.watchGrp, 'remove').and.callThrough();

      childView.destroy();
      expect(childView.watchGrp.remove).toHaveBeenCalled();
    });
github angular / templating / test / view_factory.spec.js View on Github external
it('should create a child injector and provide the view on the new injector', ()=&gt;{
    var injector = new Injector();
    var execContext = {};
    var view = new ViewFactory($('<div>a</div>')[0], []).createRootView(injector, execContext);
    expect(view.injector.parent).toBe(injector);
    expect(view.injector.get(View)).toBe(view);
  });
github angular / templating / test / view.spec.js View on Github external
beforeEach(() =&gt; {
    $rootElement = $(anchorHtml);
    anchor = $rootElement[0];
    viewPort = new ViewPort(anchor);
    a = new RootView($('<div>'+aHtml+'</div>')[0], new Injector());
    b = new RootView($('<div>'+bHtml+'</div>')[0], new Injector());
    c = new RootView($('<div>'+cHtml+'</div>')[0], new Injector());
    d = new RootView($('<div>'+dHtml+'</div>')[0], new Injector());
  });
github angular / di.js / example / node / main.js View on Github external
var di = require('di');
var Car = require('./car');


var injector = new di.Injector([]);

console.log('Getting in the car...');
var car = injector.get(Car);

car.run();

if (car.isRunning()) {
  console.log('The car is running');
} else {
  console.log('The car is stopped');
}
github angular / dgeni / lib / doc-processor.js View on Github external
function createChildInjector(baseInjector, docs) {
    var module = new di.Module();
    module.factory('injector', function() { return baseInjector; });
    if ( docs ) { module.value('docs', docs); }
    return new di.Injector([module], baseInjector);
  }
github MortenHoustonLudvigsen / KarmaTestAdapter / karma-vs-reporter / src / Commands / Discover.ts View on Github external
export function run(config: Util.Config, outputFile: string) {
    Globals.Configure({ outputFile: outputFile });
    var di = require('di');
    new di.Injector([{
        emitter: ['type', require('karma/lib/events').EventEmitter],
        config: ['value', Util.getKarmaConfig(config)],
        preprocess: ['factory', require('karma/lib/preprocessor').createPreprocessor],
        fileList: ['type', require('karma/lib/file_list').List]
    }]).invoke(discoverTests);
}