UNPKG

ts-ioc-container

Version:

Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.

29 lines (28 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AddOnConstructAsyncHookModule = exports.onConstructAsync = exports.onConstructAsyncHooksRunner = void 0; const hook_1 = require("./hook"); const HooksRunner_1 = require("./HooksRunner"); exports.onConstructAsyncHooksRunner = new HooksRunner_1.HooksRunner('onConstructAsync'); const onConstructAsync = (...fns) => (0, hook_1.hook)('onConstructAsync', ...fns); exports.onConstructAsync = onConstructAsync; class AddOnConstructAsyncHookModule { onException; constructor(onException) { this.onException = onException; } applyTo(container) { container.addOnConstructHook((instance, scope) => { if (!exports.onConstructAsyncHooksRunner.hasHooks(instance)) { return; } exports.onConstructAsyncHooksRunner.executeAsync(instance, { scope }).catch((ex) => { if (!this.onException) { throw ex; } this.onException(ex, { scope }); }); }); } } exports.AddOnConstructAsyncHookModule = AddOnConstructAsyncHookModule;