Example #1
0
    /**
     * Add a function mapping
     *
     * The provided function should be the constructor of the class
     *
     * @param fullClassName
     * @param constructor
     */
    addConstructor (fullClassName, constructor)
    {
        ensure(fullClassName, String);
        ensure(constructor, Function);

        this.constructors[fullClassName] = constructor;
    }
Example #2
0
    /**
     * Add a file mapping
     *
     * The provided file should export the constructor of the class
     *
     * @param fullClassName
     * @param filePath
     */
    addFile (fullClassName, filePath)
    {
        ensure(fullClassName, String);
        ensure(filePath, String);

        this.files[fullClassName] = filePath;
    }
Example #3
0
                .then(function (result) {
                    ensure(result, Array);

                    result[0].files.should.be.Array;

                    done();
                })
Example #4
0
                .then(function (filenames) {
                    ensure(filenames, Array);

                    ensure.isIn('app.log', filenames).should.be.true;
                    ensure.isIn('database.log', filenames).should.be.true;

                    done();
                })
Example #5
0
                .then(function (instances) {
                    ensure(instances, Array);

                    ensure.isIn('instance-abcdef01', instances).should.be.true;
                    ensure.isIn('instance-abcdef02', instances).should.be.true;

                    done();
                })
Example #6
0
    /**
     * Add a provider to the application
     *
     * @param {String|Function|ServiceProvider} provider
     */
    addProvider (provider)
    {
        // If a string is provided, we need to resolve the provider from the
        // container and then try to instantiate it
        if (ensure.isString(provider)) {
            provider = this.make(provider);
        }

        // If a function is provided, it most likely means we need to create
        // an instance of the provider
        if (ensure(provider, Function, true)) {
            var Constructor = provider;

            provider = new Constructor(this);
        }

        // Finally, check that the object is actually a service provider
        // instance
        ensure(provider, ServiceProvider);

        this.providers.push(provider);
    }