title: Multiple Database Context
body: <p>I am following this <a href="http://contosontiermvc.codeplex.com/" rel="nofollow">Contoso University MVC NTier University</a> architecture. But I don't know how to set it to multiple database context. In my MVC application, I have two database that I usually access. </p>
  
  <ul>
  <li>Project.Common (this is where put the common infrastructure like the IUnitOfWork, IRepository)</li>
  <li>Project.Data </li>
  <li>Project.Models </li>
  <li>Project.Service </li>
  <li>Project2.Data</li>
  <li>Project2.Models </li>
  <li>Project2.Service </li>
  <li>Project.Web</li>
  </ul>
  
  <p>When I use the UnityContainer in Global.asax. I Register two Dbfactory and  Uow like :</p>
  
  <pre><code>IUnityContainer oContainer = new UnityContainer()
  // ***** PROJECT *****
   .RegisterType&lt;IProjectDBFactory, ProjectDBFactory&gt;(new HttpContextLifetimeManager&lt;IProjectDBFactory&gt;())
   .RegisterType&lt;IUnitOfWork, ProjectUow&gt;(new HttpContextLifetimeManager&lt;IUnitOfWork&gt;())
   .RegisterType&lt;IRepoPRJTABLE, RepoPRJTABLE&gt;(new HttpContextLifetimeManager&lt;IRepoPRJTABLE&gt;())
   .RegisterType&lt;IServiceRepository&lt;PRJTABLE&gt;, ServicePRJTABLE&gt;(new HttpContextLifetimeManager&lt;IServiceRepository&lt;PRJTABLE&gt;&gt;())
  
   // ***** PROJECT2 *****
   .RegisterType&lt;IProject2DBFactory, Project2WebDBFactory&gt;(new HttpContextLifetimeManager&lt;IProject2DBFactory&gt;())
   .RegisterType&lt;IUnitOfWork, Project2Uow&gt;(new HttpContextLifetimeManager&lt;IUnitOfWork&gt;())
   .RegisterType&lt;IRepoPRJ2TABLE, RepoPRJ2TABLE&gt;(new HttpContextLifetimeManager&lt;IRepoPRJ2TABLE&gt;())
   .RegisterType&lt;IServiceRepository&lt;PRJ2TABLE&gt;, ServicePRJ2TABLE&gt;(new HttpContextLifetimeManager&lt;IServiceRepository&lt;PRJ2TABLE&gt;&gt;())
  </code></pre>
  
  <p>I can view the data perfectly. But when I look into the ServicePRJ, it's Unitofwork context is the for the PROJECT2. Please help me... I think I need to pass the context to the unitwork but I am having hard time constructing my code. I am new in coding with such architecture, new in using unitycontainer, new in mvc. Please help me. </p>