I would like to use a global reach action filter in my MVC 3 application using Ninject; however, I am trying to understand the lifetime of this filter, its dependency and how to make changes in its dependency by decorating my controllers and / or methods of actions.
I would like my filter type to depend on objects whose lifetime is associated with a scope request, so something like this:
public sealed class MyGlobalActionFilter : IActionFilter
{
public MyGlobalActionFilter(IService1 svc1, IService2 svc2, RequestType reqType)
{
}
}
... and in the config module ...
Bind<IService1>().To<ConcreteService1>().InRequestScope()
Bind<IService2>().To<ConcreteService2>().InRequestScope()
BindFilter<MyGlobalActionFilter>(FilterScope.Global, null)
.WhenControllerHas<RequestTypeAttribute>()
.WithConstructorArgumentFromControllerAttribute<RequestTypeAttribute>(
"reqType",
x => x.RequestType
);
BindFilter<MyGlobalActionFilter>(FilterScope.Global, null)
.WhenActionMethodHas<RequestTypeAttribute>()
.WithConstructorArgumentFromActionAttribute<RequestTypeAttribute>(
"reqType",
x => x.RequestType
);
BindFilter<MyGlobalActionFilter>(FilterScope.Global)
.When(x => true)
.WithConstructorArgument("reqType", RequestType.Undefined)
And an attribute on controllers and / or action methods to represent the "request type" for a particular application:
[RequestType(RequestType.Type1)]
public sealed class SomeController : Controller { }
, ? MyGlobalActionFilter HTTP? , , ?
, RequestType BindFilter , , , , , RequestType , a RequestTypeAttribute .
, !