Chained/Cloned containers #70
Replies: 2 comments 3 replies
-
I also like this for advanced features, like reloading settings by clearing/reloading values in the App-bound container. |
Beta Was this translation helpful? Give feedback.
-
I’ve been thinking about this quite a bit and if I read you correctly, the best, yet nontrivial move, would be to move away from registries as a first-class concept to containers all the way? IOW the moment svcs is initialized, it creates its first root container that is then passed into the app/web integrations. This container could carry system-wide dependencies like configs or engines (fixing #34) and each request would create a child container with the lifetime of the request. The full cache of a container could be a ChainMap of all parents’s caches and if the service is missing, it’s added to the local one. When a parent container is closed, it also closes all of its child containers. Child containers therefore need to know both about their parents for cache lookups and their children for cleanups. I think, it would also make testing easier, since you can clone the real container and overwrite just the factory you want to change. No need to flush upstream caches. Open questions
I think this whole proposal is basically what @elfjes has been asking for from day 1? /o\ |
Beta Was this translation helpful? Give feedback.
-
Per fedi, https://tacobelllabs.net/@astraluma/111904242641573392
I think it would be useful to have chained/cloned/inherited containers: basically, being able to have a container access the instances of another container without taking over it's cleanup.
This would allow more flexibility in using svcs in a way that reflects the lifecycle structure of the application. By which I mean, many applications have several lifecycles/scopes, and it would be good to have more options for integrating DI/IoC into that.
Basically, more scopes more good?
These could also replace singleton factories or registry-based value, since instead you could have a global root container, and could be a way to handle #26.
Beta Was this translation helpful? Give feedback.
All reactions