Is it possible to use Dependency Injection/IoC on an ASP.NET MVC FilterAttribute ?
Posted
by Pure.Krome
on Stack Overflow
See other posts from Stack Overflow
or by Pure.Krome
Published on 2010-05-11T04:44:42Z
Indexed on
2010/05/11
4:54 UTC
Read the original article
Hit count: 240
Hi folks,
I've got a simple custom FilterAttribute
which I use decorate various ActionMethods
.
eg.
[AcceptVerbs(HttpVerbs.Get)]
[MyCustomFilter]
public ActionResult Bar(...)
{ ... }
Now, I wish to add some logging to this CustomFilter Action .. so being a good boy, I'm using DI/IoC
... and as such wish to use this pattern for my custom FilterAttribute
.
So if i have the following...
ILoggingService
and wish to add this my custom FilterAttribute
.. i'm not sure how. Like, it's easy for me to do the following...
public class MyCustomFilterAttribute : FilterAttribute
{
public MyCustomFilterAttribute(ILoggingService loggingService)
{ ... }
}
But the compiler errors saying the attribute which decorates my ActionMethod
(listed above...) requires 1 arg .. so i'm just not sure what to do :(
© Stack Overflow or respective owner