Can I achieve the functionality of nested/child container with StrongInject? #173
-
I am trying to replace Unity DI container and I need to know if it is possible to implement child container functionality. Child containers allow you to register singleton instances in the scope of the child container so you can end up with multiple singletons for each child container and every instance resolved from the child container will use that singleton instance. Child containers inherit all registrations from their parent containers. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 15 replies
-
Hi @ekalchev there are various mechanisms that can be used to achieve something similar, but first I have to understand what you're trying to achieve. If the purpose is purely to reduce the scope of some dependencies, then the InstancePerResolution scope might be appropriate. This creates a new instance every time you resolve the instance at a different time (e.g. by use of a Func), but shares any instances that are all resolved at once (e.g. if both b and c depend on a, and d depends on b and c, then if you resolve d, both b and c will share instances of a. If that's not exactly what you need, please let me know more exactly what semantics you need, and I can try and guide you in the right direction. |
Beta Was this translation helpful? Give feedback.
Hi @ekalchev there are various mechanisms that can be used to achieve something similar, but first I have to understand what you're trying to achieve.
If the purpose is purely to reduce the scope of some dependencies, then the InstancePerResolution scope might be appropriate. This creates a new instance every time you resolve the instance at a different time (e.g. by use of a Func), but shares any instances that are all resolved at once (e.g. if both b and c depend on a, and d depends on b and c, then if you resolve d, both b and c will share instances of a.
If that's not exactly what you need, please let me know more exactly what semantics you need, and I can try and guide you in the rig…