@shellicar/core-di 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +110 -0
  3. package/dist/cjs/ServiceCollection.d.ts +13 -0
  4. package/dist/cjs/ServiceCollection.d.ts.map +1 -0
  5. package/dist/cjs/ServiceCollection.js +64 -0
  6. package/dist/cjs/ServiceCollection.js.map +1 -0
  7. package/dist/cjs/ServiceProvider.d.ts +22 -0
  8. package/dist/cjs/ServiceProvider.d.ts.map +1 -0
  9. package/dist/cjs/ServiceProvider.js +138 -0
  10. package/dist/cjs/ServiceProvider.js.map +1 -0
  11. package/dist/cjs/constants.d.ts +8 -0
  12. package/dist/cjs/constants.d.ts.map +1 -0
  13. package/dist/cjs/constants.js +12 -0
  14. package/dist/cjs/constants.js.map +1 -0
  15. package/dist/cjs/createServiceCollection.d.ts +3 -0
  16. package/dist/cjs/createServiceCollection.d.ts.map +1 -0
  17. package/dist/cjs/createServiceCollection.js +7 -0
  18. package/dist/cjs/createServiceCollection.js.map +1 -0
  19. package/dist/cjs/debug.d.ts +4 -0
  20. package/dist/cjs/debug.d.ts.map +1 -0
  21. package/dist/cjs/debug.js +25 -0
  22. package/dist/cjs/debug.js.map +1 -0
  23. package/dist/cjs/dependsOn.d.ts +3 -0
  24. package/dist/cjs/dependsOn.d.ts.map +1 -0
  25. package/dist/cjs/dependsOn.js +27 -0
  26. package/dist/cjs/dependsOn.js.map +1 -0
  27. package/dist/cjs/errors.d.ts +11 -0
  28. package/dist/cjs/errors.d.ts.map +1 -0
  29. package/dist/cjs/errors.js +22 -0
  30. package/dist/cjs/errors.js.map +1 -0
  31. package/dist/cjs/index.d.ts +6 -0
  32. package/dist/cjs/index.d.ts.map +1 -0
  33. package/dist/cjs/index.js +17 -0
  34. package/dist/cjs/index.js.map +1 -0
  35. package/dist/cjs/interfaces.d.ts +22 -0
  36. package/dist/cjs/interfaces.d.ts.map +1 -0
  37. package/dist/cjs/interfaces.js +19 -0
  38. package/dist/cjs/interfaces.js.map +1 -0
  39. package/dist/cjs/metadata.d.ts +5 -0
  40. package/dist/cjs/metadata.d.ts.map +1 -0
  41. package/dist/cjs/metadata.js +17 -0
  42. package/dist/cjs/metadata.js.map +1 -0
  43. package/dist/cjs/types.d.ts +35 -0
  44. package/dist/cjs/types.d.ts.map +1 -0
  45. package/dist/cjs/types.js +3 -0
  46. package/dist/cjs/types.js.map +1 -0
  47. package/dist/esm/ServiceCollection.d.ts +13 -0
  48. package/dist/esm/ServiceCollection.d.ts.map +1 -0
  49. package/dist/esm/ServiceCollection.js +60 -0
  50. package/dist/esm/ServiceCollection.js.map +1 -0
  51. package/dist/esm/ServiceProvider.d.ts +22 -0
  52. package/dist/esm/ServiceProvider.d.ts.map +1 -0
  53. package/dist/esm/ServiceProvider.js +134 -0
  54. package/dist/esm/ServiceProvider.js.map +1 -0
  55. package/dist/esm/constants.d.ts +8 -0
  56. package/dist/esm/constants.d.ts.map +1 -0
  57. package/dist/esm/constants.js +9 -0
  58. package/dist/esm/constants.js.map +1 -0
  59. package/dist/esm/createServiceCollection.d.ts +3 -0
  60. package/dist/esm/createServiceCollection.d.ts.map +1 -0
  61. package/dist/esm/createServiceCollection.js +3 -0
  62. package/dist/esm/createServiceCollection.js.map +1 -0
  63. package/dist/esm/debug.d.ts +4 -0
  64. package/dist/esm/debug.d.ts.map +1 -0
  65. package/dist/esm/debug.js +22 -0
  66. package/dist/esm/debug.js.map +1 -0
  67. package/dist/esm/dependsOn.d.ts +3 -0
  68. package/dist/esm/dependsOn.d.ts.map +1 -0
  69. package/dist/esm/dependsOn.js +23 -0
  70. package/dist/esm/dependsOn.js.map +1 -0
  71. package/dist/esm/errors.d.ts +11 -0
  72. package/dist/esm/errors.d.ts.map +1 -0
  73. package/dist/esm/errors.js +16 -0
  74. package/dist/esm/errors.js.map +1 -0
  75. package/dist/esm/index.d.ts +6 -0
  76. package/dist/esm/index.d.ts.map +1 -0
  77. package/dist/esm/index.js +5 -0
  78. package/dist/esm/index.js.map +1 -0
  79. package/dist/esm/interfaces.d.ts +22 -0
  80. package/dist/esm/interfaces.d.ts.map +1 -0
  81. package/dist/esm/interfaces.js +11 -0
  82. package/dist/esm/interfaces.js.map +1 -0
  83. package/dist/esm/metadata.d.ts +5 -0
  84. package/dist/esm/metadata.d.ts.map +1 -0
  85. package/dist/esm/metadata.js +12 -0
  86. package/dist/esm/metadata.js.map +1 -0
  87. package/dist/esm/types.d.ts +35 -0
  88. package/dist/esm/types.d.ts.map +1 -0
  89. package/dist/esm/types.js +2 -0
  90. package/dist/esm/types.js.map +1 -0
  91. package/dist/types/ServiceCollection.d.ts +13 -0
  92. package/dist/types/ServiceCollection.d.ts.map +1 -0
  93. package/dist/types/ServiceProvider.d.ts +22 -0
  94. package/dist/types/ServiceProvider.d.ts.map +1 -0
  95. package/dist/types/constants.d.ts +8 -0
  96. package/dist/types/constants.d.ts.map +1 -0
  97. package/dist/types/createServiceCollection.d.ts +3 -0
  98. package/dist/types/createServiceCollection.d.ts.map +1 -0
  99. package/dist/types/debug.d.ts +4 -0
  100. package/dist/types/debug.d.ts.map +1 -0
  101. package/dist/types/dependsOn.d.ts +3 -0
  102. package/dist/types/dependsOn.d.ts.map +1 -0
  103. package/dist/types/errors.d.ts +11 -0
  104. package/dist/types/errors.d.ts.map +1 -0
  105. package/dist/types/index.d.ts +6 -0
  106. package/dist/types/index.d.ts.map +1 -0
  107. package/dist/types/interfaces.d.ts +22 -0
  108. package/dist/types/interfaces.d.ts.map +1 -0
  109. package/dist/types/metadata.d.ts +5 -0
  110. package/dist/types/metadata.d.ts.map +1 -0
  111. package/dist/types/types.d.ts +35 -0
  112. package/dist/types/types.d.ts.map +1 -0
  113. package/package.json +66 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Stephen Hellicar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # @shellicar/core-di
2
+
3
+ A basic dependency injection library.
4
+
5
+ ## Motivation
6
+
7
+ Coming from .NET I am used to DI frameworks/libraries such as `Autofac`, `Ninject`, `StructureMap`, `Unity`, and Microsoft's own `DependencyInjection`.
8
+
9
+ I started using `InversifyJS`, and tried out some others along the way, such as `diod`.
10
+
11
+ With TypeScript 5.0 generally available with non-experimental decorators, most DI libraries have not been updated, so I decided to create my own.
12
+
13
+ ## Features
14
+
15
+ My set of features is simple, based on my current usage
16
+
17
+ * Type-safe registration.
18
+ ```ts
19
+ const services = createServiceCollection();
20
+ abstract class IAbstract { abstract method(): void; }
21
+ abstract class Concrete {}
22
+ services.register(IAbstract).to(Concrete);
23
+ // ^ Error
24
+ ```
25
+ * Type-safe resolution.
26
+ ```ts
27
+ const provider = services.buildProvider();
28
+ const svc = provider.resolve(IMyService);
29
+ // ^ IMyService
30
+ ```
31
+ * Provide factory methods for instantiating classes.
32
+ ```ts
33
+ services.register(Redis).to(Redis, x => {
34
+ const options = x.resolve(IRedisOptions);
35
+ return new Redis({
36
+ port: options.port,
37
+ host: options.host,
38
+ });
39
+ });
40
+ ```
41
+ * Use property injection with decorators for simple dependency definition.
42
+ ```ts
43
+ abstract class IDependency {}
44
+ class Service implements IService {
45
+ @dependsOn(IDependency) private readonly dependency!: IDependency;
46
+ }
47
+ ```
48
+ * Provide multiple implementations for identifiers and provide a `resolveAll` method.
49
+ * Define instance lifetime with simple builder pattern.
50
+
51
+ ```ts
52
+ services.register(IAbstract).to(Concrete).singleton();
53
+ ```
54
+
55
+ * Create scopes to allow "per-request" lifetimes.
56
+ ```ts
57
+ const services = createServiceCollection();
58
+ const provider = services.buildProvider();
59
+ using scope = provider.createScope();
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ Check the test files for different usage scenarios.
65
+
66
+ ```ts
67
+ import { dependsOn, createServiceCollection, enable } from '@shellicar/core-di';
68
+
69
+ // Define the dependency interface
70
+ abstract class IClock {
71
+ abstract now(): Date;
72
+ }
73
+ // And implementation
74
+ class DefaultClock implements IClock {
75
+ now(): Date {
76
+ return new Date();
77
+ }
78
+ }
79
+
80
+ // Define your interface
81
+ abstract class IDatePrinter {
82
+ abstract handle(): string;
83
+ }
84
+ // And implementation
85
+ class DatePrinter implements IDatePrinter {
86
+ @dependsOn(IClock) public readonly clock!: IClock;
87
+
88
+ handle(): string {
89
+ return `The time is: ${this.clock.now().toISOString()}`;
90
+ }
91
+ }
92
+
93
+ // Register and build provider
94
+ const services = createServiceCollection();
95
+ services.register(IClock).to(DefaultClock).singleton();
96
+ services.register(IDatePrinter).to(DatePrinter).scoped();
97
+ const sp = services.buildProvider();
98
+
99
+ // Optionally create a scope
100
+ using scope = sp.createScope();
101
+
102
+ // Resolve the interface
103
+ const svc = scope.resolve(IDatePrinter);
104
+ console.log(svc.handle());
105
+ ```
106
+
107
+ ## Inspired by
108
+
109
+ * [InversifyJS](https://github.com/inversify/InversifyJS)
110
+ * [Microsoft.Extensions.DependencyInjection](https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.DependencyInjection)
@@ -0,0 +1,13 @@
1
+ import type { SourceType, ServiceBuilder, ServiceDescriptor, ServiceIdentifier, Newable } from './types';
2
+ import type { IServiceCollection, IServiceModule, IServiceProvider } from './interfaces';
3
+ export declare class ServiceCollection implements IServiceCollection {
4
+ private readonly services;
5
+ constructor(services?: Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>);
6
+ registerModules(modules: Newable<IServiceModule>[]): void;
7
+ get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
8
+ register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
9
+ private addService;
10
+ clone(): IServiceCollection;
11
+ buildProvider(): IServiceProvider;
12
+ }
13
+ //# sourceMappingURL=ServiceCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServiceCollection.d.ts","sourceRoot":"","sources":["../../src/ServiceCollection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmB,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAC;AACjJ,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIzF,qBAAa,iBAAkB,YAAW,kBAAkB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,wDAA8D;IAG5F,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,GAAG,IAAI;IAOhE,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,EAAE;IAI5E,QAAQ,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAgBnF,OAAO,CAAC,UAAU;IAUX,KAAK,IAAI,kBAAkB;IAU3B,aAAa,IAAI,gBAAgB;CAIzC"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServiceCollection = void 0;
4
+ const ServiceProvider_1 = require("./ServiceProvider");
5
+ const constants_1 = require("./constants");
6
+ const debug_1 = require("./debug");
7
+ class ServiceCollection {
8
+ constructor(services = new Map()) {
9
+ Object.defineProperty(this, "services", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: services
14
+ });
15
+ }
16
+ registerModules(modules) {
17
+ modules.forEach(x => {
18
+ const module = new x();
19
+ module.registerServices(this);
20
+ });
21
+ }
22
+ get(key) {
23
+ var _a;
24
+ return (_a = this.services.get(key)) !== null && _a !== void 0 ? _a : [];
25
+ }
26
+ register(identifier) {
27
+ return {
28
+ // to: (implementation: ServiceImplementation<T>, func?: InstanceFactory<T>) => {
29
+ to: (implementation, factory) => {
30
+ const descriptor = (factory === undefined) ? { implementation: implementation, lifetime: constants_1.Lifetime.Resolve } : { implementation, factory, lifetime: constants_1.Lifetime.Resolve };
31
+ this.addService(identifier, descriptor);
32
+ const builder = {
33
+ singleton: () => { descriptor.lifetime = constants_1.Lifetime.Singleton; return builder; },
34
+ scoped: () => { descriptor.lifetime = constants_1.Lifetime.Scoped; return builder; },
35
+ transient: () => { descriptor.lifetime = constants_1.Lifetime.Transient; return builder; },
36
+ };
37
+ return builder;
38
+ },
39
+ };
40
+ }
41
+ addService(identifier, descriptor) {
42
+ (0, debug_1.log)('Adding service', { identifier, descriptor });
43
+ let existing = this.services.get(identifier);
44
+ if (existing == null) {
45
+ existing = [];
46
+ this.services.set(identifier, existing);
47
+ }
48
+ existing.push(descriptor);
49
+ }
50
+ clone() {
51
+ const clonedMap = new Map();
52
+ for (const [key, descriptors] of this.services) {
53
+ const clonedDescriptors = descriptors.map(descriptor => ({ ...descriptor }));
54
+ clonedMap.set(key, clonedDescriptors);
55
+ }
56
+ return new ServiceCollection(clonedMap);
57
+ }
58
+ buildProvider() {
59
+ const cloned = this.clone();
60
+ return new ServiceProvider_1.ServiceProvider(cloned);
61
+ }
62
+ }
63
+ exports.ServiceCollection = ServiceCollection;
64
+ //# sourceMappingURL=ServiceCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServiceCollection.js","sourceRoot":"","sources":["../../src/ServiceCollection.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAGpD,2CAAuC;AACvC,mCAA8B;AAE9B,MAAa,iBAAiB;IAC5B,YAA6B,WAAW,IAAI,GAAG,EAAoD;QAAvF;;;;mBAAiB,QAAQ;WAA8D;IACnG,CAAC;IAEM,eAAe,CAAC,OAAkC;QACvD,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YAClB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAuB,GAAyB;;QACjD,OAAO,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED,QAAQ,CAAuB,UAAgC;QAC7D,OAAO;YACL,iFAAiF;YACjF,EAAE,EAAE,CAAC,cAA+D,EAAE,OAA4B,EAAE,EAAE;gBACpG,MAAM,UAAU,GAAwB,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,cAA0C,EAAE,QAAQ,EAAE,oBAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,oBAAQ,CAAC,OAAO,EAAE,CAAC;gBACvN,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;gBACxC,MAAM,OAAO,GAAG;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AAI,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAEM,aAAa;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC5B,OAAO,IAAI,iCAAe,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACF;AAvDD,8CAuDC"}
@@ -0,0 +1,22 @@
1
+ import type { IServiceProvider, IDisposable, IServiceCollection } from './interfaces';
2
+ import { IServiceScope } from './interfaces';
3
+ import type { ServiceIdentifier, ServiceImplementation, SourceType } from './types';
4
+ type Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;
5
+ type ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;
6
+ export declare class ServiceProvider implements IServiceProvider, IServiceScope {
7
+ private services;
8
+ private singletons;
9
+ private scoped;
10
+ private created;
11
+ constructor(services: IServiceCollection, singletons?: ResolveMap<object>);
12
+ [Symbol.dispose](): void;
13
+ private resolveFrom;
14
+ private resolveInternal;
15
+ resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve?: ResolveMap<T>): T[];
16
+ resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve?: ResolveMap<T>): T;
17
+ private createInstance;
18
+ createScope(): IServiceScope & IDisposable;
19
+ private setDependencies;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=ServiceProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServiceProvider.d.ts","sourceRoot":"","sources":["../../src/ServiceProvider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAqB,qBAAqB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGvG,KAAK,EAAE,CAAC,CAAC,SAAS,UAAU,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAEhF,KAAK,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAIjF,qBAAa,eAAgB,YAAW,gBAAgB,EAAE,aAAa;IAKnE,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,UAAU;IALpB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,OAAO,CAAqB;gBAG1B,QAAQ,EAAE,kBAAkB,EAC5B,UAAU,qBAAqB;IAGzC,CAAC,MAAM,CAAC,OAAO,CAAC;IAIhB,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,eAAe;IAmBhB,UAAU,CAAC,CAAC,SAAS,UAAU,EACpC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAChC,cAAc,gBAAwB,GACrC,CAAC,EAAE;IAKC,OAAO,CAAC,CAAC,SAAS,UAAU,EACjC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAChC,cAAc,gBAAwB,GACrC,CAAC;IAiBJ,OAAO,CAAC,cAAc;IAiCf,WAAW,IAAI,aAAa,GAAG,WAAW;IAIjD,OAAO,CAAC,eAAe;CAkBxB"}
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServiceProvider = void 0;
4
+ const debug_1 = require("./debug");
5
+ const constants_1 = require("./constants");
6
+ const interfaces_1 = require("./interfaces");
7
+ const metadata_1 = require("./metadata");
8
+ const errors_1 = require("./errors");
9
+ const createResolveMap = () => new Map();
10
+ class ServiceProvider {
11
+ constructor(services, singletons = createResolveMap()) {
12
+ Object.defineProperty(this, "services", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: services
17
+ });
18
+ Object.defineProperty(this, "singletons", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: singletons
23
+ });
24
+ Object.defineProperty(this, "scoped", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: createResolveMap()
29
+ });
30
+ Object.defineProperty(this, "created", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: []
35
+ });
36
+ }
37
+ [Symbol.dispose]() {
38
+ this.created.forEach(x => x[Symbol.dispose]());
39
+ }
40
+ resolveFrom(identifier, descriptor, lifetimeMap, currentResolve) {
41
+ let resolvedInstances = lifetimeMap.get(identifier);
42
+ if (resolvedInstances === undefined) {
43
+ resolvedInstances = new Map();
44
+ lifetimeMap.set(identifier, resolvedInstances);
45
+ }
46
+ let instance = resolvedInstances.get(descriptor.implementation);
47
+ if (instance === undefined) {
48
+ instance = this.createInstance(descriptor, currentResolve);
49
+ resolvedInstances.set(descriptor.implementation, instance);
50
+ this.setDependencies(descriptor.implementation, instance, currentResolve);
51
+ }
52
+ return instance;
53
+ }
54
+ resolveInternal(identifier, descriptor, currentResolve) {
55
+ const mapping = {
56
+ [constants_1.Lifetime.Singleton]: this.singletons,
57
+ [constants_1.Lifetime.Scoped]: this.scoped,
58
+ [constants_1.Lifetime.Resolve]: currentResolve,
59
+ };
60
+ const sourceMap = mapping[descriptor.lifetime];
61
+ if (sourceMap === undefined) {
62
+ const instance = this.createInstance(descriptor, currentResolve);
63
+ this.setDependencies(descriptor.implementation, instance, currentResolve);
64
+ return instance;
65
+ }
66
+ return this.resolveFrom(identifier, descriptor, sourceMap, currentResolve);
67
+ }
68
+ resolveAll(identifier, currentResolve = createResolveMap()) {
69
+ const descriptors = this.services.get(identifier);
70
+ return descriptors.map(descriptor => this.resolveInternal(identifier, descriptor, currentResolve));
71
+ }
72
+ resolve(identifier, currentResolve = createResolveMap()) {
73
+ if (identifier.prototype === interfaces_1.IServiceScope.prototype) {
74
+ return this;
75
+ }
76
+ const descriptors = this.services.get(identifier);
77
+ if (descriptors.length === 0) {
78
+ throw new errors_1.UnregisteredServiceError(identifier);
79
+ }
80
+ if (descriptors.length > 1) {
81
+ throw new errors_1.MultipleRegistrationError(identifier);
82
+ }
83
+ const descriptor = descriptors[0];
84
+ return this.resolveInternal(identifier, descriptor, currentResolve);
85
+ }
86
+ createInstance(descriptor, currentResolve) {
87
+ let instance;
88
+ if ('factory' in descriptor) {
89
+ const factory = descriptor.factory;
90
+ const resolve = (identifier) => this.resolve(identifier, currentResolve);
91
+ const resolveAll = (identifier) => this.resolveAll(identifier, currentResolve);
92
+ const createScope = () => this.createScope();
93
+ // proxy requests to keep current resolved types
94
+ instance = factory({
95
+ resolve: resolve,
96
+ resolveAll: resolveAll,
97
+ createScope: createScope,
98
+ // [Symbol.dispose]: () => {},
99
+ });
100
+ }
101
+ else {
102
+ try {
103
+ instance = new descriptor.implementation();
104
+ }
105
+ catch (err) {
106
+ console.error(err, 'Error creating service', {
107
+ descriptor,
108
+ });
109
+ throw err;
110
+ }
111
+ }
112
+ if (descriptor.lifetime !== constants_1.Lifetime.Singleton && Symbol.dispose in instance) {
113
+ this.created.push(instance);
114
+ }
115
+ return instance;
116
+ }
117
+ createScope() {
118
+ return new ServiceProvider(this.services, this.singletons);
119
+ }
120
+ setDependencies(type, instance, currentResolve) {
121
+ var _a;
122
+ const dependencies = (_a = (0, metadata_1.getMetadata)(constants_1.DesignDependenciesKey, type)) !== null && _a !== void 0 ? _a : {};
123
+ (0, debug_1.log)('Dependencies', type.name, dependencies);
124
+ for (const [key, identifier] of Object.entries(dependencies)) {
125
+ if (identifier !== type) {
126
+ (0, debug_1.log)('Resolving', identifier, 'for', type.name);
127
+ const dep = this.resolve(identifier, currentResolve);
128
+ instance[key] = dep;
129
+ }
130
+ else {
131
+ throw new errors_1.SelfDependencyError();
132
+ }
133
+ }
134
+ return instance;
135
+ }
136
+ }
137
+ exports.ServiceProvider = ServiceProvider;
138
+ //# sourceMappingURL=ServiceProvider.js.map
@@ -0,0 +1 @@
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+ Scoped = "SCOPED",
5
+ Singleton = "SINGLETON"
6
+ }
7
+ export declare const DesignDependenciesKey = "design:dependencies";
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,SAAS,cAAc;CACxB;AAED,eAAO,MAAM,qBAAqB,wBAAwB,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DesignDependenciesKey = exports.Lifetime = void 0;
4
+ var Lifetime;
5
+ (function (Lifetime) {
6
+ Lifetime["Resolve"] = "RESOLVE";
7
+ Lifetime["Transient"] = "TRANSIENT";
8
+ Lifetime["Scoped"] = "SCOPED";
9
+ Lifetime["Singleton"] = "SINGLETON";
10
+ })(Lifetime || (exports.Lifetime = Lifetime = {}));
11
+ exports.DesignDependenciesKey = 'design:dependencies';
12
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,6BAAiB,CAAA;IACjB,mCAAuB,CAAA;AACzB,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB;AAEY,QAAA,qBAAqB,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { IServiceCollection } from './interfaces';
2
+ export declare const createServiceCollection: () => IServiceCollection;
3
+ //# sourceMappingURL=createServiceCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServiceCollection.d.ts","sourceRoot":"","sources":["../../src/createServiceCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,eAAO,MAAM,uBAAuB,QAAO,kBAAmE,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createServiceCollection = void 0;
4
+ const ServiceCollection_1 = require("./ServiceCollection");
5
+ const createServiceCollection = () => new ServiceCollection_1.ServiceCollection();
6
+ exports.createServiceCollection = createServiceCollection;
7
+ //# sourceMappingURL=createServiceCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServiceCollection.js","sourceRoot":"","sources":["../../src/createServiceCollection.ts"],"names":[],"mappings":";;;AACA,2DAAwD;AAEjD,MAAM,uBAAuB,GAAG,GAAuB,EAAE,CAAC,IAAI,qCAAiB,EAAwB,CAAC;AAAlG,QAAA,uBAAuB,2BAA2E"}
@@ -0,0 +1,4 @@
1
+ export declare const log: (message?: string, ...optionalParams: unknown[]) => void;
2
+ export declare const enable: () => void;
3
+ export declare const disable: () => void;
4
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,GAAG,aATO,MAAM,qBAAqB,OAAO,EAAE,SASjB,CAAC;AAC3C,eAAO,MAAM,MAAM,YAA6B,CAAC;AACjD,eAAO,MAAM,OAAO,YAA8B,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disable = exports.enable = exports.log = void 0;
4
+ class DebugLogger {
5
+ constructor() {
6
+ Object.defineProperty(this, "debugging", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: false
11
+ });
12
+ }
13
+ enable() { this.debugging = true; }
14
+ disable() { this.debugging = false; }
15
+ log(message, ...optionalParams) {
16
+ if (this.debugging) {
17
+ console.log(message, ...optionalParams);
18
+ }
19
+ }
20
+ }
21
+ const logger = new DebugLogger();
22
+ exports.log = logger.log.bind(logger);
23
+ exports.enable = logger.enable.bind(logger);
24
+ exports.disable = logger.disable.bind(logger);
25
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":";;;AACA,MAAM,WAAW;IAAjB;QACU;;;;mBAAY,KAAK;WAAC;IAS5B,CAAC;IAPQ,MAAM,KAAK,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC;IACnC,OAAO,KAAK,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC;IACrC,GAAG,CAAC,OAAgB,EAAE,GAAG,cAAyB;QACvD,IAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAClB,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF;AAED,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;AAEpB,QAAA,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9B,QAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACpC,QAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ServiceIdentifier, SourceType } from './types';
2
+ export declare const dependsOn: <T extends SourceType>(identifier: ServiceIdentifier<T>) => (value: undefined, ctx: ClassFieldDecoratorContext) => (this: object, initialValue: any) => any;
3
+ //# sourceMappingURL=dependsOn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependsOn.d.ts","sourceRoot":"","sources":["../../src/dependsOn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAY7D,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,UAAU,cAAc,iBAAiB,CAAC,CAAC,CAAC,aAC/D,SAAS,OAAO,0BAA0B,YAChC,MAAM,gBAAgB,GAAG,QAUnD,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dependsOn = void 0;
4
+ const constants_1 = require("./constants");
5
+ const metadata_1 = require("./metadata");
6
+ const tagProperty = (metadataKey, annotationTarget, name, identifier) => {
7
+ let existing = (0, metadata_1.getMetadata)(metadataKey, annotationTarget);
8
+ if (existing === undefined) {
9
+ existing = {};
10
+ (0, metadata_1.defineMetadata)(metadataKey, existing, annotationTarget);
11
+ }
12
+ existing[name] = identifier;
13
+ };
14
+ const dependsOn = (identifier) => {
15
+ return (value, ctx) => {
16
+ return function (initialValue) {
17
+ if (Reflect.getMetadata === undefined) {
18
+ throw new Error('Please import reflect-metadata');
19
+ }
20
+ const target = this.constructor;
21
+ tagProperty(constants_1.DesignDependenciesKey, target, ctx.name, identifier);
22
+ return initialValue;
23
+ };
24
+ };
25
+ };
26
+ exports.dependsOn = dependsOn;
27
+ //# sourceMappingURL=dependsOn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependsOn.js","sourceRoot":"","sources":["../../src/dependsOn.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AAEpD,yCAAyD;AAEzD,MAAM,WAAW,GAAG,CAAuB,WAAmB,EAAE,gBAAwB,EAAE,IAAqB,EAAE,UAAgC,EAAE,EAAE;IACnJ,IAAI,QAAQ,GAAG,IAAA,sBAAW,EAAI,WAAW,EAAE,gBAAgB,CAAC,CAAC;IAC7D,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,QAAQ,GAAG,EAAE,CAAC;QACd,IAAA,yBAAc,EAAC,WAAW,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IACD,QAAQ,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;AAC9B,CAAC,CAAC;AAEK,MAAM,SAAS,GAAG,CAAuB,UAAgC,EAAE,EAAE;IAClF,OAAO,CAAC,KAAgB,EAAE,GAA+B,EAAE,EAAE;QAC3D,OAAO,UAAwB,YAAiB;YAC9C,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;gBACtC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;YACpD,CAAC;YAED,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;YAChC,WAAW,CAAC,iCAAqB,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YACjE,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,SAAS,aAYpB"}
@@ -0,0 +1,11 @@
1
+ import type { ServiceIdentifier } from './types';
2
+ export declare class UnregisteredServiceError<T extends object> extends Error {
3
+ constructor(identifier: ServiceIdentifier<T>);
4
+ }
5
+ export declare class MultipleRegistrationError<T extends object> extends Error {
6
+ constructor(identifier: ServiceIdentifier<T>);
7
+ }
8
+ export declare class SelfDependencyError extends Error {
9
+ constructor();
10
+ }
11
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,qBAAa,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,KAAK;gBACvD,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;CAG7C;AAED,qBAAa,yBAAyB,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,KAAK;gBACxD,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;CAG7C;AAED,qBAAa,mBAAoB,SAAQ,KAAK;;CAI7C"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SelfDependencyError = exports.MultipleRegistrationError = exports.UnregisteredServiceError = void 0;
4
+ class UnregisteredServiceError extends Error {
5
+ constructor(identifier) {
6
+ super(`Resolving service that has not been registered: ${identifier}`);
7
+ }
8
+ }
9
+ exports.UnregisteredServiceError = UnregisteredServiceError;
10
+ class MultipleRegistrationError extends Error {
11
+ constructor(identifier) {
12
+ super(`Multiple services have been registered: ${identifier}`);
13
+ }
14
+ }
15
+ exports.MultipleRegistrationError = MultipleRegistrationError;
16
+ class SelfDependencyError extends Error {
17
+ constructor() {
18
+ super('Service depending on itself');
19
+ }
20
+ }
21
+ exports.SelfDependencyError = SelfDependencyError;
22
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAEA,MAAa,wBAA2C,SAAQ,KAAK;IACnE,YAAY,UAAgC;QAC1C,KAAK,CAAC,mDAAmD,UAAU,EAAE,CAAC,CAAC;IACzE,CAAC;CACF;AAJD,4DAIC;AAED,MAAa,yBAA4C,SAAQ,KAAK;IACpE,YAAY,UAAgC;QAC1C,KAAK,CAAC,2CAA2C,UAAU,EAAE,CAAC,CAAC;IACjE,CAAC;CACF;AAJD,8DAIC;AAED,MAAa,mBAAoB,SAAQ,KAAK;IAC5C;QACE,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACvC,CAAC;CACF;AAJD,kDAIC"}
@@ -0,0 +1,6 @@
1
+ export { createServiceCollection } from './createServiceCollection';
2
+ export { dependsOn } from './dependsOn';
3
+ export { IDisposable, IServiceCollection, IServiceModule, IServiceProvider, IServiceScope } from './interfaces';
4
+ export type { AbstractNewable, InstanceFactory, LifetimeBuilder, MetadataType, Newable, ServiceBuilder, ServiceDescriptor, ServiceDescriptorConcrete, ServiceDescriptorFactory, ServiceIdentifier, ServiceImplementation, ServiceModuleType, SourceType, } from './types';
5
+ export { enable, disable, } from './debug';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAChH,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,UAAU,GAAG,MAAM,SAAS,CAAC;AAC1Q,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,SAAS,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disable = exports.enable = exports.IServiceScope = exports.IServiceProvider = exports.IServiceModule = exports.IServiceCollection = exports.IDisposable = exports.dependsOn = exports.createServiceCollection = void 0;
4
+ var createServiceCollection_1 = require("./createServiceCollection");
5
+ Object.defineProperty(exports, "createServiceCollection", { enumerable: true, get: function () { return createServiceCollection_1.createServiceCollection; } });
6
+ var dependsOn_1 = require("./dependsOn");
7
+ Object.defineProperty(exports, "dependsOn", { enumerable: true, get: function () { return dependsOn_1.dependsOn; } });
8
+ var interfaces_1 = require("./interfaces");
9
+ Object.defineProperty(exports, "IDisposable", { enumerable: true, get: function () { return interfaces_1.IDisposable; } });
10
+ Object.defineProperty(exports, "IServiceCollection", { enumerable: true, get: function () { return interfaces_1.IServiceCollection; } });
11
+ Object.defineProperty(exports, "IServiceModule", { enumerable: true, get: function () { return interfaces_1.IServiceModule; } });
12
+ Object.defineProperty(exports, "IServiceProvider", { enumerable: true, get: function () { return interfaces_1.IServiceProvider; } });
13
+ Object.defineProperty(exports, "IServiceScope", { enumerable: true, get: function () { return interfaces_1.IServiceScope; } });
14
+ var debug_1 = require("./debug");
15
+ Object.defineProperty(exports, "enable", { enumerable: true, get: function () { return debug_1.enable; } });
16
+ Object.defineProperty(exports, "disable", { enumerable: true, get: function () { return debug_1.disable; } });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,2CAAgH;AAAvG,yGAAA,WAAW,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAAE,2GAAA,aAAa,OAAA;AAEzF,iCAA2C;AAAlC,+FAAA,MAAM,OAAA;AAAE,gGAAA,OAAO,OAAA"}
@@ -0,0 +1,22 @@
1
+ import type { SourceType, ServiceBuilder, ServiceDescriptor, ServiceIdentifier, ServiceModuleType } from './types';
2
+ export declare abstract class IDisposable {
3
+ abstract [Symbol.dispose]: () => void;
4
+ }
5
+ export declare abstract class IServiceModule {
6
+ abstract registerServices(services: IServiceCollection): void;
7
+ }
8
+ export declare abstract class IServiceScope {
9
+ abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;
10
+ abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];
11
+ }
12
+ export declare abstract class IServiceProvider extends IServiceScope {
13
+ abstract createScope(): IServiceScope & IDisposable;
14
+ }
15
+ export declare abstract class IServiceCollection {
16
+ abstract get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
17
+ abstract register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
18
+ abstract registerModules(modules: ServiceModuleType[]): void;
19
+ abstract buildProvider(): IServiceProvider;
20
+ abstract clone(): IServiceCollection;
21
+ }
22
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnH,8BAAsB,WAAW;IAC/B,SAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CAC9C;AAED,8BAAsB,cAAc;aAClB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;CACrE;AAED,8BAAsB,aAAa;aACjB,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC;aAClE,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;CACxF;AAED,8BAAsB,gBAAiB,SAAQ,aAAa;aAC1C,WAAW,IAAI,aAAa,GAAG,WAAW;CAC3D;AAED,8BAAsB,kBAAkB;aACtB,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,EAAE;aAC5E,QAAQ,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;aACnF,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,IAAI;aACnD,aAAa,IAAI,gBAAgB;aACjC,KAAK,IAAI,kBAAkB;CAC5C"}