How to use di - 10 common examples

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 angular / templating / test / compiler.spec.js View on Github external
describe('Compiler', ()=>{
  var selector:Selector,
      container,
      binders,
      attrDirectiveAnnotations;

  it('should not reparent nodes', inject(Compiler, (compiler)=>{
    createSelector();
    container = $('<div>a</div>')[0];
    var node = container.childNodes[0];
    compiler._compile(container.childNodes, selector);
    expect(node.parentNode).toBe(container);
  }));

  describe('mark nodes with directives and collect binders', ()=&gt; {
    it('should work for one element', function() {
      createSelector([ new DecoratorDirective({selector: '[name]'}) ]);

      // all possible combinations of elements with decorators and elements
      // without decorators
      compileAndVerifyBinders('<div></div>', '()');
      compileAndVerifyBinders('<div name="1"></div>', '(),1()');
    });
github angular / di.js / example / coffee / electric_heater.js View on Github external
import {Provide} from 'di';

import {Heater} from './heater';

@Provide(Heater)
export class ElectricHeater {
  constructor() {}

  on() {
    // console.log('Turning on electric heater...');
  }

  off() {
    // console.log('Turning off electric heater...');
  }
}
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 RackHD / on-dhcp-proxy / lib / packet.js View on Github external
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
 */

// Modified from http://github.com/apaprocki/node-dhcpjs

"use strict";

var di = require('di'),
    v4 = require('ipv6').v4;

module.exports = PacketFactory;
di.annotate(PacketFactory, new di.Provide('DHCP.packet'));
di.annotate(PacketFactory, new di.Inject('DHCP.protocol', 'Services.Configuration', '_'));
function PacketFactory(protocol, configuration, _) {
    var packetFunctions = {
        // Expose this for test
        createPacketBuffer: createPacketBuffer,
        createProxyDhcpAck: function(clientPacket, bootFileName) {
            var packet = {};
            var isPXEefi = false;
            _.forEach(clientPacket, function(value, key) {
                packet[key] = value;
            });
            packet.op = protocol.BOOTPMessageType.BOOTPREPLY.value;
            packet.htype = protocol.ARPHardwareType.HW_ETHERNET.value;
            packet.fname = bootFileName;

            // Necessary, at least on vbox
            packet.siaddr = configuration.get('tftpBindAddress', '10.1.1.1');
github RackHD / on-dhcp-proxy / lib / server.js View on Github external
// Copyright 2015, EMC, Inc.

"use strict";

var di = require('di'),
    dgram = require('dgram');

module.exports = serverFactory;
di.annotate(serverFactory, new di.Provide('DHCP.Proxy.Server'));
di.annotate(serverFactory, new di.Inject(
        'Services.Core',
        'DHCP.messageHandler',
        'DHCP.IscDhcpLeasePoller',
        'Logger'
    )
);
function serverFactory(core, messageHandler, IscDhcpLeasePoller, Logger) {
    var logger = Logger.initialize(Server);

    function Server(inPort, outPort, address) {
        this.server = dgram.createSocket('udp4');
        this.inPort = inPort;
        this.outPort = outPort.LegacyPort;
        this.outportEFI = outPort.EFIPort;
        this.address = address;
    }
github RackHD / on-dhcp-proxy / lib / message-handler.js View on Github external
// Copyright 2015, EMC, Inc.

"use strict";

var di = require('di');

module.exports = messageHandlerFactory;
di.annotate(messageHandlerFactory, new di.Provide('DHCP.messageHandler'));
di.annotate(messageHandlerFactory, new di.Inject(
        'DHCP.packet',
        'DHCP.parser',
        'Services.Lookup',
        'Services.Configuration',
        'Protocol.Task',
        'Services.Waterline',
        'Logger',
        'Assert',
        'Errors',
        'Promise',
        '_'
    )
);
function messageHandlerFactory(
    packetUtil,
    parser,
github RackHD / on-dhcp-proxy / lib / parser.js View on Github external
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE
 */

// Modified from http://github.com/apaprocki/node-dhcpjs

"use strict";

var di = require('di');

module.exports = ParserFactory;

di.annotate(ParserFactory, new di.Provide('DHCP.parser'));
di.annotate(ParserFactory, new di.Inject('DHCP.protocol', 'Logger', 'Assert'));

function ParserFactory(protocol, Logger, assert) {
    return {
        logger: Logger.initialize(ParserFactory),
        len: null,

        trimNulls: function(str) {
            var idx = str.indexOf('\u0000');
            return (-1 === idx) ? str : str.substr(0, idx);
        },

        readIpRaw: function(msg, offset) {
            if (0 === msg.readUInt8(offset) || msg.length &lt; 4) {
                return undefined;
            }