ts-ioc-container
Version:
Typescript IoC container
44 lines (43 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.depKey = exports.isDepKey = void 0;
const Registration_1 = require("./registration/Registration");
const Provider_1 = require("./provider/Provider");
const isDepKey = (key) => {
return typeof key === 'object' && key !== null && 'key' in key;
};
exports.isDepKey = isDepKey;
const depKey = (key) => {
const scopePredicates = [];
const mappers = [];
return {
key,
asKey: (registration) => {
let reg = registration.pipe(...mappers).bindToKey(key);
if (scopePredicates.length > 0) {
reg = registration.when(...scopePredicates);
}
return reg;
},
register: (fn) => {
let registration = new Registration_1.Registration(() => new Provider_1.Provider(fn), key).pipe(...mappers);
if (scopePredicates.length > 0) {
registration = registration.when(...scopePredicates);
}
return registration;
},
resolve: (s) => s.resolveOne(key),
pipe(...values) {
mappers.push(...values);
return this;
},
when(...predicates) {
scopePredicates.push(...predicates);
return this;
},
asAlias(r) {
return r.bindToAlias(key);
},
};
};
exports.depKey = depKey;