UNPKG

@tdi2/di-core

Version:

TypeScript Dependency Injection 2 - Core DI framework

114 lines (113 loc) 2.96 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/decorators.ts function Service(options = {}) { return function(target) { target.__di_service__ = { // Token is now optional - will be auto-generated from interface name token: options.token || null, scope: options.scope || "singleton", autoResolve: options.token === void 0, ...options }; }; } __name(Service, "Service"); function Inject(token) { return function(target, propertyKey, parameterIndex) { if (!target.__di_inject__) { target.__di_inject__ = []; } target.__di_inject__.push({ token, propertyKey, parameterIndex, target: target.constructor?.name || target.name, autoResolve: token === void 0 }); }; } __name(Inject, "Inject"); var Autowired = Inject; function AutoWireService(options = {}) { return Service({ ...options, // Force auto-resolution for AutoWireService token: options.token || void 0 }); } __name(AutoWireService, "AutoWireService"); function AutoWireInject(token) { return Inject(token); } __name(AutoWireInject, "AutoWireInject"); function Profile(...profiles) { return function(target) { if (!target.__di_service__) { target.__di_service__ = {}; } target.__di_service__.profiles = profiles; }; } __name(Profile, "Profile"); function Scope(scope) { return function(target) { if (!target.__di_service__) { target.__di_service__ = {}; } target.__di_service__.scope = scope; }; } __name(Scope, "Scope"); function Optional(target, propertyKey, parameterIndex) { if (!target.__di_inject__) { target.__di_inject__ = []; } const lastInject = target.__di_inject__[target.__di_inject__.length - 1]; if (lastInject && lastInject.parameterIndex === parameterIndex) { lastInject.optional = true; } } __name(Optional, "Optional"); function Primary(target) { if (!target.__di_service__) { target.__di_service__ = {}; } target.__di_service__.primary = true; } __name(Primary, "Primary"); function Qualifier(qualifier) { return function(target, propertyKey, parameterIndex) { if (propertyKey !== void 0 || parameterIndex !== void 0) { if (!target.__di_inject__) { target.__di_inject__ = []; } const lastInject = target.__di_inject__[target.__di_inject__.length - 1]; if (lastInject) { lastInject.qualifier = qualifier; } } else { if (!target.__di_service__) { target.__di_service__ = {}; } target.__di_service__.qualifier = qualifier; } }; } __name(Qualifier, "Qualifier"); export { AutoWireInject, AutoWireService, Autowired, Inject, Autowired as LegacyAutowired, Inject as LegacyInject, Service as LegacyService, Optional, Primary, Profile, Qualifier, Scope, Service }; //# sourceMappingURL=decorators.js.map