1
我已经看到了很多关于如何在Asp.Net MVC中通过使用ActionFilter或DI包将会话注入到控制器中的请求来设置会话的文章。我想知道的是,会是一个坏主意/模式只是让喜欢的扩展方法:从控制器获取Nhibernate ISession(每个会话请求)ASP.Net MVC
public static ISession GetNHibernateSession(this Controller controller)
{
return SessionFactory.OpenSession();
}
以便在需要像当会话可以被实例化:
public ActionResult DoSomething()
{
using( var session = this.GetNHibernateSession())
{
// Do something with the session
}
}
原因这可能是一个好/坏主意,将不胜感激