<commit_before>/* 
 * Dependency Injection Container (currently unused)
 *
 */

const argsList = require('args-list'); // reads function params at init

module.exports = function () {
    const dic = {};
    const factories = {};
    const deps = {};

    // sounds worse than it is...
    dic.factory = function(name, factory) {
        factories[name] = factory;
    }

    dic.register = function(name, dep) {
        deps[name] = dep;
    }

    dic.get = function(name) {
        if(!deps[name]) {
            let factory = factories[name];
            // ensure factory exists then inject it
            deps[name] = factory && dic.inject(factory);
            if(!deps[name]) {
                throw new Error('Module not found: ' + name);
            }
        }
        return deps[name];
    }

    dic.inject = function(factory) {
        let args = argsList(factory)
            .map(function(dep) {
                return dic.get(dep);
            });
    }
}<commit_msg>return factory from dic.inject<commit_after>/* 
 * Dependency Injection Container (currently unused)
 *
 */

const argsList = require('args-list'); // reads function params at init

module.exports = function () {
    const dic = {};
    const factories = {};
    const deps = {};

    // sounds worse than it is...
    dic.factory = function(name, factory) {
        factories[name] = factory;
    }

    dic.register = function(name, dep) {
        deps[name] = dep;
    }

    dic.get = function(name) {
        if(!deps[name]) {
            let factory = factories[name];
            // ensure factory exists then inject it
            deps[name] = factory && dic.inject(factory);
            if(!deps[name]) {
                throw new Error('Module not found: ' + name);
            }
        }
        return deps[name];
    }

    dic.inject = function(factory) {
        let args = argsList(factory)
            .map(function(dep) {
                return dic.get(dep);
            });
        return factory.apply(null, args);
    }
}
{'fraction_non_alphanumeric': 0.1322150962012827, 'fraction_numerical': 0.0, 'mean_word_length': 1.8049792531120332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3452760', 'n_tokens_mistral': 589, 'n_tokens_neox': 573, 'n_words': 144}