Dependency Injection on ResponseModelFilter

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...
container.RegisterType<IMyNewClass, MyNewClass>();

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
        // Summary:
        //     Initializes a new instance of the System.Web.Http.Filters.ActionFilterAttribute
        //     class.
        protected ActionFilterAttributeCustom(IMyNewClass myNewClass)

I return to the container configuration and add...
            container.RegisterType<ActionFilterAttributeCustom, ResponseModelFilter>(
                 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?
Who is Participating?
//replace dhObj and with your name
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EEUnityIOC
    public class ResponseModelFilter : ActionFilterAttributeCustom
        private readonly IdhObj _dhObj;
        //Constructor for Dep Injection
        public ResponseModelFilter(IdhObj dhObj) : base(dhObj)
            _dhObj = dhObj;
gswitzAuthor Commented:
I found this...

Now, on all the controller classes that have
How can I go about using Unity to resolve the dependency for the constructor?
gswitzAuthor Commented:
This isn't the answer at all, but it's nice to give the points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.