I have this DDD application that has MVC on the Presentation, with Ninject.
I have the CrossCutting Layer binding the injections from all the layers, and it works like a charm.
What i can't make work, is when it comes to Filter Attributes. I have this filter that checks one cookie and depending on it's value, executes queries on the Database. With this Architecture, i just can't make my Filter access my Repository directly, it would be disrespectful to the methodology i'm applying.
I have my IFooAppService interface and have it's methods that eventually will hit the repository for Data requesting. I can successfully inject it in any Controller constructor and it will execute my _fooAppService.Query(), but i have this XooFilter above some actions in my application, and i just can't pass my _fooAppService to it. Here's my XooFilter:
public class XooFilter : ActionFilterAttribute
{
private readonly IFooAppService _fooAppService;
public XooFilter(IFooAppService fooAppService)
{
_fooAppService = fooAppService;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// LOGIC...
var fooValue = _fooAppService.Query();
// MORE LOGIC..
}
}
But, when i insert my filter above any Action [XooFilter], it won't work. It says the filter has no constructor with 0 elements.
I just can't figure it out how to do it nicely and keep the characteristics from DDD and IoC. I found the article below, but couldn't find any answer:
Injecting dependencies into ASP.NET MVC 3 action filters. What's wrong with this approach?