I need to make a change to an app using dependency injection.
The change goes into the ResponseModelFilter. I could new up my class and do my work right there, but I was thinking, to keep with the spirit of DI, I should use the container to create the object.
I'm using Unity.
I created an interface for my new class.
I created my new class inheriting from the interface.
I added this to the configuration of the container...
I created a new abstract class ActionFilterAttributeCustom which inherits from ActionFilterAttribute and has a Constructor that takes my new class.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public abstract class ActionFilterAttributeCustom : ActionFilterAttribute
// Initializes a new instance of the System.Web.Http.Filters.ActionFilterAttribute
protected ActionFilterAttributeCustom(IMyNewClass myNewClass)
I return to the container configuration and add...
new InjectionConstructor(new ResolvedParameter<IMyNewClass>())
I alter the ResponseModelFilter to inherit from ActionFilterAttributeCustom and create a constructor that takes IMyNewClass
private readonly IMyNewClass _myNewClass;
//Constructor for Dep Injection
public ResponseModelFilter (IMyNewClass myNewClass)
_myNewClass = myNewClass;
Now, the build is largely successful except every class with
before the public class declaration
Error 6 'ResponseModelFilter' does not contain a constructor that takes 0 arguments.
I'm not sure how to alter these Controller classes.
Is it possible that I need a controller factory to resolve this issue?
Now, on all the controller classes that have
How can I go about using Unity to resolve the dependency for the constructor?