title: Microsoft Unity - How to register connectionstring as a parameter to repository constructor when it can vary by client?
body: <p>I am relatively new to IoC containers so I apologize in advance for my ignorance.</p>
  
  <p>My application is a asp.net 4.0 MVC app that uses the Entity Framework with a  Repository layer on top of that.  It is a multi tenant application so the connection string that is used varies by the logged in client.</p>
  
  <p>The connection string is determined by a 'key' that gets passed in as part of the route which indicates the client.  This route data is only present on the first request of the user's session.</p>
  
  <p>The route looks kind of like this: http://{host}/login/dev/</p>
  
  <p>where 'dev' indicates we are using the dev database.</p>
  
  <p>Currently the IoC container is registering all dependencies in the global.asax Application_Start event handler and I have the 'key' hardcoded as follows:</p>
  
  <pre><code>var cnString = CommonServices.GetDBConnection("dev");
  container.RegisterType&lt;IRequestMgmtRecipientRepository, RequestMgmtRecipientRepository&gt;(
          new InjectionConstructor(cnString));
  </code></pre>
  
  <p>Is there a way with Unity to dynamically register the repository based on the logged in client using the route data that is supplied initially?</p>
  
  <p>Note:  I am not manually resolving the repositories.  They are getting constructed by the container when the controllers get instantiated.
  I am stumped.</p>
  
  <p>Thanks!</p>