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
[ResponseModelFilter]
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?
gswitzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gswitzAuthor Commented:
I found this...
http://stackoverflow.com/questions/14649545/how-to-inject-constructor-in-controllers-by-unity-on-mvc-4

Now, on all the controller classes that have
[ResponseModelFilter]
How can I go about using Unity to resolve the dependency for the constructor?
0
kblauCommented:
//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;
        }
    }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gswitzAuthor Commented:
This isn't the answer at all, but it's nice to give the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.