Is there anyway to recover gracefully in an ASP.NET MVC application if the database is not found for some reason when I try to get an instance of my NHibernate Session from Structuremap?
public static class StructureMap
{
private static Configuration Cfg
{
get
{
var configuration = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nhibernate.config"));
configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionStringName, "MyConnectionString");
return configuration;
}
}
public static void ConfigureStuctureMap()
{
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<ISessionFactory>()
.CacheBy(InstanceScope.Singleton)
.TheDefault.Is.ConstructedBy(Cfg.BuildSessionFactory);
x.ForRequestedType<ISession>()
.CacheBy(InstanceScope.HttpContext)
.TheDefault.Is.ConstructedBy(c => c.GetInstance<NHibernateSessionFactory>().GetCurrentSession());
});
}
}
Right now the application will display a runtime error YSOD. I have a custom static html error page setup in the web config but it doesn't display even though I have the custom errors mode set to "On"