How to use the di.Provide 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 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 RackHD / on-dhcp-proxy / lib / dhcp-protocol.js View on Github external
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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 = ProtocolFactory;
di.annotate(module.exports, new di.Provide('DHCP.protocol'));
function ProtocolFactory() {
    var createEnum = function (v, n) {
        function Enum(value, name) {
            this.value = value;
            this.name = name;
        }

        Enum.prototype.toString = function () {
            return this.name;
        };
        Enum.prototype.valueOf = function () {
            return this.value;
        };
        return Object.freeze(new Enum(v, n));
    };
github RackHD / on-dhcp-proxy / lib / isc-dhcp-lease-poller.js View on Github external
// Copyright 2016, EMC, Inc.

'use strict';

var di = require('di');

module.exports = iscDhcpLeasePollerFactory;
di.annotate(iscDhcpLeasePollerFactory, new di.Provide('DHCP.IscDhcpLeasePoller'));
di.annotate(iscDhcpLeasePollerFactory, new di.Inject(
    'Services.Lookup',
    'Services.Configuration',
    'Logger',
    'Promise',
    'Assert',
    'Tail',
    '_',
    'PromiseQueue'
));

function iscDhcpLeasePollerFactory(
    lookupService,
    configuration,
    Logger,
    Promise,
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 angular / templating / src / lib / di / ce_di.js View on Github external
function created() {
    var self = this;

    // Use the element as "this" for custom elements
    function proxy() {
      type.apply(self, arguments);
      return self;
    }

    proxy.annotations = type.annotations || [];
    proxy.annotations.push(new Provide(type));
    proxy.parameters = type.parameters;
    var localProviders = [proxy, ...providers];
    if (this.classList.contains('ng-binder')) {
      // This is a hook for angular templates to provide additional providers,
      // e.g. decorator directives, ...
      this.ngInjectorFactory = injectorFactory;
    } else {
      injectorFactory([]);
    }

    function injectorFactory(extraProviders = []) {
      localProviders.push(...extraProviders);
      var injector = rootInjector.createChild({
        node: self, providers: localProviders, isShadowRoot: false
      });
      injector.get(type);
github RackHD / on-dhcp-proxy / lib / packet.js View on Github external
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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
github chrisguttandin / standardized-audio-context / test / unit / unpatched-audio-context.js View on Github external
it('should return the unprefixed AudioContext even if there is a prefixed version as well', function () {
        function FakeWindow() {
            return {
                AudioContext: AudioContext,
                webkitAudioContext: webkitAudioContext
            };
        }

        di.annotate(FakeWindow, new di.Provide(Window));

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

        expect(injector.get(UnpatchedAudioContext)).to.equal(AudioContext);
    });
github chrisguttandin / standardized-audio-context / test / unit / is-supported.js View on Github external
beforeEach(function () {
        tests = {
            promises: true,
            typedarrays: true,
            webaudio: true
        };

        function FakeModernizr() {
            return tests;
        }

        di.annotate(FakeModernizr, new di.Provide(Modernizr));

        injector = new di.Injector([
            FakeModernizr
        ]);
    });
github angular / di.js / example / kitchen-di / mock_heater.js View on Github external
import {Provide} from 'di';
import {Heater} from './coffee_maker/heater';

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

  on() {
    console.log('Turning on the MOCK heater...');
  }

  off() {}
}
github angular / di.js / example / coffee / mock_heater.js View on Github external
import {Provide} from 'di';

import {Heater} from './heater';

@Provide(Heater)
export class MockHeater {
  on() {}
  off() {}
}