@clawject/di
Version:
<p align="center"> <a href="https://clawject.com/" target="_blank"><img src="https://clawject.com/img/logo.svg" align="center" alt="Clawject Logo" width="120" height="120" /></a> </p>
42 lines (41 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SingletonScope = void 0;
const Utils_1 = require("../Utils");
class SingletonScope {
constructor() {
this.scopedInstances = new Map();
}
registerScopeBeginCallback(callback) {
// do nothing
}
removeScopeBeginCallback(callback) {
// do nothing
}
get(name, objectFactory) {
if (this.scopedInstances.has(name)) {
return this.scopedInstances.get(name);
}
const object = objectFactory.getObject();
if (Utils_1.Utils.isPromise(object)) {
const promiseObject = object.then(resolvedObject => {
this.scopedInstances.set(name, resolvedObject);
return resolvedObject;
});
this.scopedInstances.set(name, promiseObject);
return promiseObject;
}
this.scopedInstances.set(name, object);
return object;
}
remove(name) {
const object = this.scopedInstances.get(name);
this.scopedInstances.delete(name);
return object ?? null;
}
registerDestructionCallback(name, callback) { }
useProxy() {
return false;
}
}
exports.SingletonScope = SingletonScope;