How to use the di.Inject 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 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 / 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 < 4) {
                return undefined;
            }
github angular / di.js / example / kitchen-di / coffee_maker / heater.js View on Github external
import {Inject} from 'di';
import {Electricity} from '../electricity';

@Inject(Electricity)
export class Heater {
  constructor(electricity) {
    this.electricity = electricity;
  }

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

  off() {
    console.log('Turning off the coffee heater...');
  }
}
github angular / di.js / example / kitchen-di / coffee_maker / grinder.js View on Github external
import {Inject} from 'di';
import {Electricity} from '../electricity';

@Inject(Electricity)
export class Grinder {
  constructor(electricity) {
    this.electricity = electricity;
  }

  grind() {
    console.log('Grinding coffee beans...');
  }
}
github angular / di.js / example / kitchen-di / dishwasher.js View on Github external
import {Inject} from 'di';
import {Electricity} from './electricity';

@Inject(Electricity)
export class Dishwasher {
  constructor(electricity) {
    this.electricity = electricity;
  }

  add(item) {
    console.log('Putting ' + item + ' into the dishwasher...');
  }
  wash() {
    console.log('Running the dishwasher...');
  }
}
github angular / di.js / example / kitchen-di / kitchen.js View on Github external
import {Inject} from 'di';
import {CoffeeMaker} from './coffee_maker/coffee_maker';
import {Skillet} from './skillet';
import {Stove} from './stove';
import {Fridge} from './fridge';
import {Dishwasher} from './dishwasher';

@Inject(CoffeeMaker, Skillet, Stove, Fridge, Dishwasher)
export class Kitchen {
  constructor(coffeeMaker, skillet, stove, fridge, dishwasher) {
    this.coffeeMaker = coffeeMaker;
    this.skillet = skillet;
    this.stove = stove;
    this.fridge = fridge;
    this.dishwasher = dishwasher;
  }

  makeScrambledEggs() {
    console.log('Making some eggs...');
    this.skillet.add(this.fridge.getEggs());
    this.stove.add(this.skillet);
    this.stove.on();
    this.stove.off();
    console.log('Scrambled eggs are ready.');
github angular / di.js / example / kitchen-di / fridge.js View on Github external
import {Inject} from 'di';
import {Electricity} from './electricity';

@Inject(Electricity)
export class Fridge {
  constructor(electricity) {
    this.electricity = electricity;
  }

  getEggs() {
    return '3 eggs';
  }
}