Created
August 20, 2010 09:22
-
-
Save ArnisL/539955 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Interreg.Web.Bootstrap{ | |
using System; | |
using Config; | |
using Microsoft.Practices.ServiceLocation; | |
using MvcExtensions; | |
using NHibernate; | |
using NHibernate.Context; | |
using StructureMap; | |
public class NHibernateTask:BootstrapperTask{ | |
private readonly IContainer _container; | |
public NHibernateTask(IContainer container){ | |
if(container==null) throw new ArgumentNullException(); | |
_container=container; | |
} | |
public override TaskContinuation Execute(){ | |
NHibernateBootstrap.SpinIt(_container); | |
return TaskContinuation.Continue; | |
} | |
} | |
public class NHibernatePerRequestTask:PerRequestTask{ | |
private readonly ISessionFactory _factory; | |
private readonly IServiceLocator _locator; | |
public NHibernatePerRequestTask(IServiceLocator locator){ | |
if(locator==null) throw new ArgumentNullException(); | |
_locator=locator; | |
_factory=_locator.GetInstance<ISessionFactory>(); | |
} | |
public override TaskContinuation Execute(){ | |
CurrentSessionContext.Bind(_factory.OpenSession()); | |
return TaskContinuation.Continue; | |
} | |
protected override void DisposeCore(){ | |
_factory.GetCurrentSession().Flush(); | |
CurrentSessionContext.Unbind(_factory); | |
base.DisposeCore(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment