UNPKG

ts-bakery

Version:

Baked dependency injection for Typescript.

44 lines 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const DependencyRegistration_1 = require("./DependencyRegistration"); class DependencyRegistrationBuilder { constructor(cstr) { this._isSingle = false; this._isLazy = true; this._restrictions = new Set(); this._constructor = cstr; this._name = cstr.name; } build() { return new DependencyRegistration_1.default(this._constructor, this._name, this._isSingle, this._isLazy, Array.from(this._restrictions)); } /** * Will only ever create one single instance of this object. * @returns */ asSingle() { this._isSingle = true; return this; } /** * Will restrict injection of this type only to types within restriction. * @param restrictions * @returns */ restrictTo(...restrictions) { for (const constructor of restrictions) { this._restrictions.add(constructor.name); } return this; } /** * Will create an instance immediately after its dependecies have been resolved. * @returns */ nonLazy() { this._isLazy = false; return this; } } exports.default = DependencyRegistrationBuilder; //# sourceMappingURL=DependencyRegistrationBuilder.js.map