I’m looking for a DI solution to help me manage object associations for situations where the object associations need to be set based on other member values within the same object.
So, given an object association where an Employee object has an AddressId Property and related Address association Property how can I externally manage these associations in a way that allows each class to remain loosely coupled?
My first attempt was to use an IoC container. I stopped using this approach after realizing I would need to extend my container so that it is able to resolve type instances based on decision logic stored in IoC configuration – that just seems like a bad idea. (Injecting the container into the repository would work but would break my compositional root so that’s off the table too.) With that said, I don’t think this is a job for an IoC container – convince me otherwise.
I did some research and found a paper by Andy Bulka called Relationship Manager. Bulka's design calls for a mediating class that manages the associations. I’m not sure if this is the best approach.
I’m sure someone in the community has tackled this before. What are the DI best practices related to this design problem?