I read carefully the documentation about provider and some other Github issues (typically #418). It seems the only way to inject an asynchronous module is to inject a provider and then call this provider to get the actual module. (For instance: http://stackoverflow.com/questions/40880447/how-to-inject-an-asynchronous-dependency-in-inversify)
However it requires the functions to be async and thus return a promise.
In my use-case we're defining a Config class that needs to be initialized asynchronously (typically, the config will fetch values from an external service). Almost all the other modules require this config. Therefore it is not a viable solution to change all the public methods into async methods just to be able to use the await this.init(); trick.
I took the Inversify basic example and I extended it to show this use-case:
https://github.com/Pyo25/inversify-basic-example/tree/asynchronous_config_dependency
Particularly, the EpicBattle class has to return a Promise<string> but that something we should avoid. (cfr: https://github.com/Pyo25/inversify-basic-example/blob/asynchronous_config_dependency/src/entities/battle/epic_battle.ts)
So, my questions are:
- is it the only way to inject an asynchronous dependency?
- do you see any workaround we could use?
Thanks for your help
I read carefully the documentation about provider and some other Github issues (typically #418). It seems the only way to inject an asynchronous module is to inject a provider and then call this provider to get the actual module. (For instance: http://stackoverflow.com/questions/40880447/how-to-inject-an-asynchronous-dependency-in-inversify)
However it requires the functions to be
asyncand thus return a promise.In my use-case we're defining a
Configclass that needs to be initialized asynchronously (typically, the config will fetch values from an external service). Almost all the other modules require this config. Therefore it is not a viable solution to change all the public methods into async methods just to be able to use theawait this.init();trick.I took the Inversify basic example and I extended it to show this use-case:
https://github.com/Pyo25/inversify-basic-example/tree/asynchronous_config_dependency
Particularly, the
EpicBattleclass has to return aPromise<string>but that something we should avoid. (cfr: https://github.com/Pyo25/inversify-basic-example/blob/asynchronous_config_dependency/src/entities/battle/epic_battle.ts)So, my questions are:
Thanks for your help