Skip to content

Commit 2069ccc

Browse files
author
Julien Heller
committed
Add asyncInitialization option to Service decorator
1 parent b2e0a2f commit 2069ccc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/decorators/Service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ export function Service<T, K extends keyof T>(optionsOrServiceName?: ServiceOpti
102102
service.multiple = (optionsOrServiceName as ServiceOptions<T, K>).multiple;
103103
service.global = (optionsOrServiceName as ServiceOptions<T, K>).global || false;
104104
service.transient = (optionsOrServiceName as ServiceOptions<T, K>).transient;
105+
service.asyncInitialization = (optionsOrServiceName as ServiceOptions<T, K>).asyncInitialization;
105106

106107
} else if (optionsOrServiceName) { // ServiceOptions
107108
service.id = (optionsOrServiceName as ServiceOptions<T, K>).id;
108109
service.factory = (optionsOrServiceName as ServiceOptions<T, K>).factory;
109110
service.multiple = (optionsOrServiceName as ServiceOptions<T, K>).multiple;
110111
service.global = (optionsOrServiceName as ServiceOptions<T, K>).global || false;
111112
service.transient = (optionsOrServiceName as ServiceOptions<T, K>).transient;
113+
service.asyncInitialization = (optionsOrServiceName as ServiceOptions<T, K>).asyncInitialization;
112114
}
113115

114116
Container.set(service);

src/types/ServiceMetadata.ts

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

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

0 commit comments

Comments
 (0)