Created
March 11, 2011 16:25
-
-
Save hyrmn/866127 to your computer and use it in GitHub Desktop.
This file contains 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
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