ActionFilterAttribute ninject injection - DbContext has been disposed

后端 未结 1 425
长发绾君心
长发绾君心 2021-01-18 01:47

I have my project which uses the usual Repository pattern with Services and Unit of Work (all with Ninject injecting the dependencies from a NinjectModule), but I\'m trying

1条回答
  •  囚心锁ツ
    2021-01-18 02:14

    I found the solution to my problem in the following question: Injecting dependencies into ASP.NET MVC 3 action filters. What's wrong with this approach?

    Combining Mark Seeman's answer with striplingwarrior's comment was the solution to it.

    Basically I splitted my ActionFilterAttribute into an Attribute that merely decorated my Actions and keeps the parameters I need for later, and also into an ActionFilter that checked the Action's custom attributes and if my attribute exists, then it injects the data I wanted from the DB into the ViewBag. Everything is later binded with the BindFilter extension from Ninject so it applies only to the methods it needs.

    0 讨论(0)
提交回复
热议问题