(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "../core/types", "./ServiceCollection"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.Register = void 0;
    var types_1 = require("../core/types");
    var ServiceCollection_1 = require("./ServiceCollection");
    var globalNS = (typeof global === "undefined") ? window : global;
    function evalGlobal(path) {
        if (typeof path === "string") {
            var r = globalNS;
            for (var _i = 0, _a = path.split("."); _i < _a.length; _i++) {
                var iterator = _a[_i];
                r = r[iterator];
                if (r === undefined || r === null) {
                    return r;
                }
            }
            return r;
        }
        return path;
    }
    function Register(id, scope) {
        return function (target) {
            if (typeof id === "object") {
                if (scope) {
                    id.scope = scope;
                }
                ServiceCollection_1.ServiceCollection.instance.register(id.for || target, id.for ? function (sp) { return sp.create(target); } : null, id.scope || ServiceCollection_1.Scope.Transient, id.id);
                if (id.mockOrInject) {
                    if (id.mockOrInject.inject) {
                        types_1.DI.inject(target, id.mockOrInject.inject);
                    }
                    else if (id.mockOrInject.mock) {
                        types_1.DI.mockType(target, id.mockOrInject.mock);
                    }
                    else if (id.mockOrInject.globalVar) {
                        ServiceCollection_1.ServiceCollection.instance.register(id.for || target, function (sp) { return evalGlobal(id.mockOrInject.globalVar); }, id.scope || ServiceCollection_1.Scope.Global, id.id);
                    }
                }
                return;
            }
            ServiceCollection_1.ServiceCollection.instance.register(target, null, scope, id);
        };
    }
    exports.Register = Register;
});
//# sourceMappingURL=Register.js.map