Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC 3, Unity 2 - Per Request Lifetime Manager
    primarykey
    data
    text
    <p>I'm using the Unity MVC3 code at <a href="http://unitymvc3.codeplex.com/" rel="nofollow">http://unitymvc3.codeplex.com/</a> to have a NHibernate session per request instance of my IUnitOfWork. </p> <p>It was working a few weeks ago, I've made some changes, and now my IUnitOfWork appears to have a static lifetime.</p> <p>From my global.asax.cs:</p> <pre><code>private static IUnitOfWorkFactory _UoWFactory = new UnitOfWorkFactory(Enums.Databases.MyDBName) .AddMapping&lt;DepartmentMap&gt;() .CompleteConfiguration(); /// &lt;summary&gt; /// Configure Unity Application Block /// &lt;/summary&gt; private void ConfigureUnity() { CIUnity.UnityContainer.Container = new UnityContainer() .RegisterType(typeof(IRepository&lt;&gt;), typeof(Repository&lt;&gt;)) .RegisterType&lt;IUnitOfWork, UnitOfWork&gt;(Enums.Databases.MyDBName.ToString(), new HierarchicalLifetimeManager(), new InjectionConstructor(Enums.Databases.MyDBName)) .RegisterInstance&lt;IUnitOfWorkFactory&gt;(Enums.Databases.MyDBName.ToString(), _UoWFactory); DependencyResolver.SetResolver(new UnityDependencyResolver(CIUnity.UnityContainer.Container)); } </code></pre> <p><code>ConfigureUnity()</code> is called from my <code>Application_Start()</code></p> <p>Heres me test code from my HomeController constructor:</p> <pre><code>private IUnitOfWork uow; private IUnitOfWork uow2; public HomeController() { uow = CIUnity.Container.Resolve&lt;IUnitOfWork&gt;(Enums.Databases.MyDBName.ToString()); IRepository&lt;Employee&gt; repo = uow.GetRepository&lt;Employee&gt;(); uow2 = CIUnity.Container.Resolve&lt;IUnitOfWork&gt;(Enums.Databases.MyDBName.ToString()); IRepository&lt;Department&gt; deptrepo = uow2.GetRepository&lt;Department&gt;(); var q = from a in repo.Find() select a; var d = from b in deptrepo.Find() select b; } </code></pre> <p>... the IUnitOfWork is resolved to the same instance, however, on subsequent page requests, a new IUnitOfWork is not created... but the code works, so its somehow registering / pulling the object so that it acts static.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload