0
有沒有辦法在ASP.NET MVC應用程序中正常恢復,如果因爲某種原因找不到數據庫時,我嘗試從Structuremap獲取NHibernate會話的實例?異常處理與結構圖
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());
});
}
}
現在的應用程序將顯示一個運行時錯誤YSOD。我有一個自定義的靜態HTML錯誤頁面設置在網絡配置,但它不顯示,即使我有自定義錯誤模式設置爲「開」