I want to dependency inject an attribute in ASP.NET MVC using Spring.Net, my attribute is something like this (note this is all pseudo code I've just typed in)...
public class InjectedAttribute : ActionFilterAttribute
{
private IBusinessLogic businessLogic;
public InjectedAttribute(IBusinessLogic businessLogic)
{
this.businessLogic = businessLogic;
}
public override void OnActionExecuting(ActionExecutedContext filterContext)
{
// do something with the business logic
businessLogic.DoSomethingImportant();
}
}
I'm using a controller factory to create the Controllers which are also injected with various business logic objects. I'm getting the controllers from the IoC container like this...
ContextRegistry.GetContext().GetObject("MyMVCController");
I'm configuring my Controllers like so passing in the business logic
<object name="MyMVCController" type="MyMVC.MyMVCController, MyMVC">
<constructor-arg index="0" ref="businessLogic" />
</object>
Is there a way to configure the injection of the attributes? I don't really want to put this into my attributes...
public class InjectedAttribute : ActionFilterAttribute
{
private IBusinessLogic businessLogic;
public InjectedAttribute(IBusinessLogic businessLogic)
{
this.businessLogic = ContextRegistry.GetContext().GetObject("businessLogic");
}
....