title: How do I managing loosely coupled object associations that are dependent on member values using DI?
body: <p>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.</p>
  
  <p><img src="https://i.stack.imgur.com/GVEap.png" alt="enter image description here"></p>
  
  <p>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?</p>
  
  <p>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.</p>
  
  <p>I did some research and found a paper by Andy Bulka called <a href="http://www.andypatterns.com/index.php/design_patterns/relationship_manager/" rel="nofollow noreferrer">Relationship Manager</a>.  Bulka's design calls for a mediating class that manages the associations.  I’m not sure if this is the best approach.</p>
  
  <p>I’m sure someone in the community has tackled this before.  What are the DI best practices related to this design problem?</p>