ASP.NET MVC 3, Action Filters, and Autofac Dependency Injection

前端 未结 2 1025
一整个雨季
一整个雨季 2021-01-02 17:02

On ASP.NET MVC 2 I have an ActionFilterAttribute called [Transaction] that starts an NHibernate transaction before executing the a

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-02 17:48

    Oh yuck.... Nicholas, you might need to store your ISession and Transaction in HttpContext.Items, which you should be able to get to via the ActionExecutedContext/ActionExecutingContext (perhaps setting it in the OnActionExecuting event handler), instead of keeping them in instance members. Either that, or you could call a ServiceLocator inside your filter to grab them for you (also yuck).

    Now I have to go look through my MVC 3 code and see if I have any similar problems myself!

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题