Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Created March 11, 2011 16:25
Show Gist options
  • Save hyrmn/866127 to your computer and use it in GitHub Desktop.
Save hyrmn/866127 to your computer and use it in GitHub Desktop.
public class SuperSecretMvcApplication : TurbineApplication
{
public virtual IContainer CreateContainer()
{
return ObjectFactory.Container;
}
public override void Startup()
{
log4net.Config.XmlConfigurator.Configure();
var container = CreateContainer();
if (IsActiveRecordRequired())
{
DomainInitializer.StartUp(HttpContext.Current.Server.MapPath("~/ActiveRecord.config"));
ConfigureContainerForActiveRecord(container);
}
ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator(container));
new LoggingModule().Init(this);
base.Startup();
}
private void ConfigureContainerForActiveRecord(IContainer container)
{
container.Configure(i =>
{
i.For<ISessionFactory>().Singleton().Use(
ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof(object)));
i.For<ISession>().Use(ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(typeof(ActiveRecordBase)));
});
}
//Note: This is to get around a Turbine 2.1 / StructureMap issue. Remove when we go to Turbine 2.2
protected override void ShutdownContext()
{
CurrentContext = null;
ServiceLocator = null;
}
protected void Application_EndRequest()
{
ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
}
//Default is true
private bool IsActiveRecordRequired()
{
var enabledValue = ConfigurationManager.AppSettings["activeRecordRequired"];
bool enabled;
if (!bool.TryParse(enabledValue, out enabled))
{
enabled = true;
}
return enabled;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment