@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>
28 lines (27 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScopeManager = void 0;
class ScopeManager {
constructor(applicationBeanFactory) {
this.applicationBeanFactory = applicationBeanFactory;
this.callbacks = new WeakMap();
}
init() {
const scopeToScopedApplicationBeans = this.applicationBeanFactory.scopeToScopedApplicationBeans;
for (const [scope] of scopeToScopedApplicationBeans) {
const callback = () => this.applicationBeanFactory.initScopedBeans(scope);
this.callbacks.set(scope, callback);
scope.registerScopeBeginCallback(callback);
}
}
destroy() {
const scopeToScopedApplicationBeans = this.applicationBeanFactory.scopeToScopedApplicationBeans;
for (const [scope] of scopeToScopedApplicationBeans) {
const callback = this.callbacks.get(scope);
if (callback) {
scope.removeScopeBeginCallback(callback);
}
}
}
}
exports.ScopeManager = ScopeManager;