How to use the di.Module 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 / dgeni / src / Dgeni.ts View on Github external
configureInjector() {

    if ( !this.injector ) {

      // Sort the packages by their dependency - ensures that services and configs are loaded in the
      // correct order
      const packages: Package[] = this.packages = sortByDependency(this.packages, 'namedDependencies');

      // Create a module containing basic shared services
      this.stopOnProcessingError = true;
      const dgeniModule = new di.Module()
        .value('dgeni', this)
        .factory('log', logFactory)
        .factory('getInjectables', getInjectablesFactory);

      // Create the dependency injection container, from all the packages' modules
      const modules = packages.map(pkg => pkg.module);
      modules.unshift(dgeniModule);

      // Create the injector and
      const injector = this.injector = new di.Injector(modules);

      // Apply the config blocks
      packages.forEach((pkg) => pkg.configFns.forEach((configFn) => injector.invoke(configFn)));

      // Get the the processors and event handlers
      const processorMap = {};
github angular / dgeni / lib / doc-processor.js View on Github external
if ( processor.runBefore && !_.isArray(processor.runBefore) ) {
      throw new Error('Error in processor "' + processor.name + '" - runBefore must be an array');
    }
    _.forEach(processor.runBefore, function(dependency) {
      depGraph.addDependency(dependency, processor.name);
    });
  });
  processors = _.map(depGraph.overallOrder(), function(processorName) {
    log.debug('processor:', processorName);
    return processorMap[processorName];
  });

  // Create the dependency injection container
  var baseInjector;
  var injectables = new di.Module();
  injectables.value('config', config);
  injectables.factory('extraData', function(injector) {
    return injector._instances;
  });

  var diModules = [injectables];

  // Ådd the exports for each processor into the injector
  _.forEach(processors, function getInjectables(processor) {
    if ( processor.exports ) {
      diModules.push(processor.exports);
    }
  });

  // Initialize the processors, passing them the config object
  // and the injectables, so they can register new things with the injector
github angular / dgeni / lib / Dgeni.js View on Github external
Dgeni.prototype.configureInjector = function() {

  var dgeni = this;

  if ( !dgeni.injector ) {

    // Sort the packages by their dependency - ensures that services and configs are loaded in the
    // correct order
    var packages = dgeni.packages = sortByDependency(dgeni.packages, 'namedDependencies');

    // Create a module containing basic shared services
    dgeni.stopOnProcessingError = true;
    var dgeniModule = new di.Module()
      .value('dgeni', dgeni)
      .factory('log', require('./util/log'))
      .factory('getInjectables', require('./util/getInjectables'));

    // Create the dependency injection container, from all the packages' modules
    var modules = packages.map(function(package) { return package.module; });
    modules.unshift(dgeniModule);

    // Create the injector and
    var injector = dgeni.injector = new di.Injector(modules);

    // Apply the config blocks
    packages.forEach(function(package) {
      package.configFns.forEach(function(configFn) {
        injector.invoke(configFn);
      });
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);
  }