ts-bakery
Version:
Baked dependency injection for Typescript.
35 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class DependencyRegistration {
constructor(constructorReference, name, isSingle, isLazy, restrictions) {
this.constructorReference = constructorReference;
this.name = name;
this.isSingle = isSingle;
this.isLazy = isLazy;
this.restrictions = restrictions;
if (constructorReference == null) {
throw new Error('Trying to pass null as constructor reference.');
}
}
get hasRestrictions() {
return this.restrictions.length > 0;
}
setBinding(binding) {
if (this.name != binding.implementation) {
throw new Error(`Binding does not match registration name ${this.name}.`);
}
this.binding = binding;
}
matchesBinding(dependencyName) {
return this.binding.abstraction == dependencyName
|| this.binding.implementation == dependencyName;
}
canBeRequestedBy(config) {
if (!this.hasRestrictions) {
return true;
}
return this.restrictions.includes(config.name);
}
}
exports.default = DependencyRegistration;
//# sourceMappingURL=DependencyRegistration.js.map