Mimic Unity child container behavior #579
Replies: 3 comments 1 reply
-
@djymdmannen Hi there. I am not familiar with the Unity behavior. But I would imagine that cloning of the registrations from the parent provides the better stability and isolation for the child. If you need to add the new registration to the parent and make it visible in the children, you may try to either rethink it :-) and implement this dynamic behavior via other abstraction (and avoid DI completely). Or you may do some clever things like holding the references to child containers near the parent and duplicate the registrations into them. Basically, it all depends on the use-case. I can help if you provide more details or better a sample code. |
Beta Was this translation helpful? Give feedback.
-
Thanks for a quick answer! I agree. For the sake of stability and determinism I'd prefer that registrations are done fully in the parent container before the children are created. But I need to address that as a separate issue. There's not much sample code to show, but maybe these two tests can illustrate what I'm after:
The last assert in the last test fails. And of course, If I use |
Beta Was this translation helpful? Give feedback.
-
Ok, thanks! I was thinking of something along those lines as well. Need to do some testing and see. :) |
Beta Was this translation helpful? Give feedback.
-
I'm trying out DryIoc as a replacement for Unity, and I can't quite figure out how to mimic the behavior of child containers in Unity.
In Unity the registrations actively flow from the parent container to any child containers, but not from the child containers to the parent container.
In DryIoc I've so far only been able to either clone the registrations or fully share the registrations. (parent <-> children). Anyone got any pointers for me?
Beta Was this translation helpful? Give feedback.
All reactions