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.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AddOnConstructHookModule = exports.onConstruct = exports.onConstructHooksRunner = void 0; const hook_1 = require("./hook"); const HooksRunner_1 = require("./HooksRunner"); exports.onConstructHooksRunner = new HooksRunner_1.HooksRunner('onConstruct'); const onConstruct = (...fns) => (0, hook_1.hook)('onConstruct', ...fns); exports.onConstruct = onConstruct; class AddOnConstructHookModule { onException; constructor(onException) { this.onException = onException; } applyTo(container) { container.addOnConstructHook((instance, scope) => { try { exports.onConstructHooksRunner.execute(instance, { scope }); } catch (ex) { if (!this.onException) { throw ex; } this.onException(ex, { scope }); } }); } } exports.AddOnConstructHookModule = AddOnConstructHookModule;