You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know is something like this is possible (but it would be great, maybe i just missed it in docs) to do when using loadModules so you can setup lifetime, resolutionMode or register per imported module.
For example, something like this:
classFooService{// Either this solutionstaticresolveConfig(){return{lifetime: awilix.Lifetime.SINGLETON,resolutionMode: awilix.ResolutionMode.CLASSIC}}barMethod(){}}// ... or this solution// (probably this one because it can be applied on both functions and classes)FooService.lifetime=awilix.Lifetime.SINGLETON;FooService.resolutionMode: awilix.ResolutionMode.CLASSIC;
This way you would have total flexibility to setup imports when using automatic module loading.
The text was updated successfully, but these errors were encountered:
You're not the first one to request this, so maybe it's worth implementing.
The counter argument though, is that now you're introducing a hard dependency on Awilix in userland code, which is pretty ironic for a DI container if you ask me; your services should not know about any DI framework, but I guess in the end it's up to the consumer to draw that line.
Now, we need to make sure we don't hog keys that may be ambiguous with something you might otherwise use for your own code, so maybe using a symbol is a good approach.
My proposed API:
import{Lifetime,ResolutionMode,REGISTRATION}from'awilix'// ClassesexportdefaultclassFooService{static[REGISTRATION]={// All of these are optionallifetime: Lifetime.SCOPED,resolutionMode: ResolutionMode.CLASSIC,register: asClass}}// FunctionsexportdefaultfunctionmakeFooService{// ...}makeFooService[REGISTRATION]={// All of these are optionallifetime: Lifetime.TRANSIENT,resolutionMode: ResolutionMode.PROXY,register: asFunction}
Hey there,
i love your library. Great work! :)
I don't know is something like this is possible (but it would be great, maybe i just missed it in docs) to do when using loadModules so you can setup
lifetime
,resolutionMode
orregister
per imported module.For example, something like this:
This way you would have total flexibility to setup imports when using automatic module loading.
The text was updated successfully, but these errors were encountered: