Skip to content

Commit 8908613

Browse files
Julien HellerNoNameProvided
authored andcommitted
Add asyncInitialization option to Service decorator
1 parent 4e2ceb1 commit 8908613

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/decorators/service.decorator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ export function Service<T, K extends keyof T>(
173173
service.multiple = (optionsOrServiceName as ServiceOptions<T, K>).multiple;
174174
service.global = (optionsOrServiceName as ServiceOptions<T, K>).global || false;
175175
service.transient = (optionsOrServiceName as ServiceOptions<T, K>).transient;
176+
service.asyncInitialization = (optionsOrServiceName as ServiceOptions<T, K>).asyncInitialization;
176177
} else if (optionsOrServiceName) {
177178
// ServiceOptions
178179
service.id = (optionsOrServiceName as ServiceOptions<T, K>).id;
179180
service.factory = (optionsOrServiceName as ServiceOptions<T, K>).factory;
180181
service.multiple = (optionsOrServiceName as ServiceOptions<T, K>).multiple;
181182
service.global = (optionsOrServiceName as ServiceOptions<T, K>).global || false;
182183
service.transient = (optionsOrServiceName as ServiceOptions<T, K>).transient;
184+
service.asyncInitialization = (optionsOrServiceName as ServiceOptions<T, K>).asyncInitialization;
183185
}
184186

185187
Container.set(service);

src/interfaces/service-metadata.interface..ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export interface ServiceMetadata<T, K extends keyof T> {
4040
*/
4141
factory?: [Constructable<T>, K] | ((...params: any[]) => any);
4242

43+
/**
44+
* Will call instance's #initialize method and resolve the promise it returns when getting with Container.getAsync() and Container.getManyAsync().
45+
*/
46+
asyncInitialization?: boolean;
47+
4348
/**
4449
* Instance of the target class.
4550
*/

src/interfaces/service-options.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ export interface ServiceOptions<T, K extends keyof T> {
3131
* Factory used to produce this service.
3232
*/
3333
factory?: [Constructable<T>, K] | ((...params: any[]) => any);
34+
35+
/**
36+
* Will call instance's #initialize method and resolve the promise it returns when getting with Container.getAsync() and Container.getManyAsync().
37+
*/
38+
asyncInitialization?: boolean;
3439
}

0 commit comments

Comments
 (0)