lib/dependency.injector.js
function loadModule(modulePath, moduleStack, options) {
        var newModule, i;
        options = options || {};

        // if modulePath is null return null
        if (!modulePath) {
            return null;
        }

        // if actual flapjack sent in as the module path then switch things around so modulePath name is unique
        if (_.isFunction(modulePath)) {
            options.flapjack = modulePath;
            modulePath = 'module-' + (new Date()).getTime();
        }
        // if we already have a flapjack, make the modulePath unique per the options
        else if (options.flapjack) {
            modulePath = (options.app || 'common') + '.' + modulePath + '.' + (options.type || 'default');
        }
        // else we need to get code from the file system, so check to see if we need to switch a mapped name to its path
        else if (this.aliases[modulePath]) {
            modulePath = this.aliases[modulePath];
        }
        // if module name already in the stack, then circular reference
        moduleStack = moduleStack || [];


        if (moduleStack.indexOf(modulePath) >= 0) {
            throw new Error('Circular reference since ' + modulePath + ' is in ' + JSON.stringify(moduleStack));
        }
        // add the path to the stack so we don't have a circular dependency
        moduleStack.push(modulePath);

        // try to find a factory that can create/get a module for the given path

        for (i = 0; this.factories && i < this.factories.length; i++) {
            if (this.factories[i].isCandidate(modulePath, options)) {
                newModule = this.factories[i].create(modulePath, moduleStack, options);
                break;
            }
        }

        // if no module found log error
        if (!newModule && moduleStack && moduleStack.length > 1) {
            /* eslint no-console:0 */
            console.log('ERROR: ' + moduleStack[moduleStack.length - 2] + ' dependency ' + modulePath + ' not found.');
        }

        // pop the current item off the stack
        moduleStack.pop();

        // return the new module (or the default {} if no factories found)
        return newModule;
    }
function loadModule(modulePath, moduleStack, options) {
        var newModule, i;
        options = options || {};

        // if modulePath is null return null
        if (!modulePath) {
            return null;
        }

        // if actual flapjack sent in as the module path then switch things around so modulePath name is unique
        if (_.isFunction(modulePath)) {
            options.flapjack = modulePath;
            modulePath = 'module-' + (new Date()).getTime();
        }
        // if we already have a flapjack, make the modulePath unique per the options
        else if (options.flapjack) {
            modulePath = (options.app || 'common') + '.' + modulePath + '.' + (options.type || 'default');
        }
        // else we need to get code from the file system, so check to see if we need to switch a mapped name to its path
        else if (this.aliases[modulePath]) {
            modulePath = this.aliases[modulePath];
        }
        // if module name already in the stack, then circular reference
        moduleStack = moduleStack || [];


        if (moduleStack.indexOf(modulePath) >= 0) {
            throw new Error('Circular reference since ' + modulePath + ' is in ' + JSON.stringify(moduleStack));
        }
        // add the path to the stack so we don't have a circular dependency
        moduleStack.push(modulePath);

        // try to find a factory that can create/get a module for the given path

        for (i = 0; this.factories && i < this.factories.length; i++) {
            if (this.factories[i].isCandidate(modulePath, options)) {
                newModule = this.factories[i].create(modulePath, moduleStack, options);
                break;
            }
        }

        // if no module found log error
        if (!newModule && moduleStack && moduleStack.length > 1) {
            /* eslint no-console:0 */
            console.log('ERROR: ' + moduleStack[moduleStack.length - 2] + ' dependency ' + modulePath + ' not found.');
        }

        // pop the current item off the stack
        moduleStack.pop();

        // return the new module (or the default {} if no factories found)
        return newModule;
    }
function loadModule ( modulePath , moduleStack , options ) { var newModule , i ; options = options || { } ; // if modulePath is null return null if ( ! modulePath ) { return null ; } // if actual flapjack sent in as the module path then switch things around so modulePath name is unique if ( _ . isFunction ( modulePath ) ) { options . flapjack = modulePath ; modulePath = 'module-' + ( new Date ( ) ) . getTime ( ) ; } // if we already have a flapjack, make the modulePath unique per the options else if ( options . flapjack ) { modulePath = ( options . app || 'common' ) + '.' + modulePath + '.' + ( options . type || 'default' ) ; } // else we need to get code from the file system, so check to see if we need to switch a mapped name to its path else if ( this . aliases [ modulePath ] ) { modulePath = this . aliases [ modulePath ] ; } // if module name already in the stack, then circular reference moduleStack = moduleStack || [ ] ; if ( moduleStack . indexOf ( modulePath ) >= 0 ) { throw new Error ( 'Circular reference since ' + modulePath + ' is in ' + JSON . stringify ( moduleStack ) ) ; } // add the path to the stack so we don't have a circular dependency moduleStack . push ( modulePath ) ; // try to find a factory that can create/get a module for the given path for ( i = 0 ; this . factories && i < this . factories . length ; i ++ ) { if ( this . factories [ i ] . isCandidate ( modulePath , options ) ) { newModule = this . factories [ i ] . create ( modulePath , moduleStack , options ) ; break ; } } // if no module found log error if ( ! newModule && moduleStack && moduleStack . length > 1 ) { /* eslint no-console:0 */ console . log ( 'ERROR: ' + moduleStack [ moduleStack . length - 2 ] + ' dependency ' + modulePath + ' not found.' ) ; } // pop the current item off the stack moduleStack . pop ( ) ; // return the new module (or the default {} if no factories found) return newModule ; }
Load a module using the pancakes injector. The injector relies on a number of factories to do the actual
injection. The first factory that can handle a given modulePath input attempts to generate an object
or return something from cache that can then be returned back to the caller.

@param modulePath Path to module
@param moduleStack Stack of modules in recursive call (to prevent circular references)
@param options Optional values used by some factories
Load a module using the pancakes injector . The injector relies on a number of factories to do the actual injection . The first factory that can handle a given modulePath input attempts to generate an object or return something from cache that can then be returned back to the caller .