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 to access a service from an ActionFilterAttribute
to inject some information (from DB) in the layout of the pages I show so I don't need to mess with all the actions on each controller.
The problem comes when I save to DB on one screen and move to the next and then come back to the previous (with a standard @Url.Action
): The ActionFilterAttribute
for the Index
action is triggered but the call to the service and corresponding repository (within the attribute) throw an exception because the DbContext has been disposed
.
Is there any problem with accessing a service and, consequently, the DbContext
from an ActionFilterAttribute
while injecting the service via Property Injection? I want to make a note that I use property injection for the service in the attribute because the constructor receives 2 parameters that are arbitrary depending on the signature of the Action methods, so my only option was to inject via property.
Let me know if you need some code and I'll update the question.