I am working with and mvc4 web application and using spring.net v2 M2 for the dependency injection.
I am wondering is possible to inject in to my controllers, filters/attributes on to the controller?
I am working with and mvc4 web application and using spring.net v2 M2 for the dependency injection.
I am wondering is possible to inject in to my controllers, filters/attributes on to the controller?
Same as in Asp.Net MVC3: Register a custom spring aware FilterAttributeFilterProvider
derive your application from SpringMvcApplication
instead of HttpApplication
and see the magic work. Sample impl. not production ready:
public class FilterProvider : FilterAttributeFilterProvider, IApplicationContextAware
{
public IApplicationContext ApplicationContext
{
set;
get;
}
public override IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
var filters = base.GetFilters(controllerContext, actionDescriptor);
foreach (var filter in filters)
{
ApplicationContext.ConfigureObject(filter.Instance, filter.Instance.GetType().Name);
yield return filter;
}
}
}