1

I have no idea why Unity is not injecting or something is ignoring the fact that I have parameters in my constructors. I saw this post, but it talks more about NinJect, but leads me to believe maybe there is a similar issue with Unity and Vs2012. I know Unity is working, because in my Application_Start code, after my unity registrations, I resolve an interface from unity and get back all the objects need. I just have no clue why my controller's constructor with parameters is being ignored. I register the controller with unity as well. When I try to hit that controller I get the No parameterless constructor defined for this object. error.

I am curious if anyone else has run into this same issue.

3
  • 1
    What sort of 'controller' are you talking about? Is that an System.Web.Mvc.Controller or a System.Web.Http.ApiController? And what is your current registration? How do you register your IDependencyResolver? Commented Sep 26, 2012 at 18:43
  • 1
    without any code, seems difficult to help you... Commented Sep 26, 2012 at 19:28
  • @Steven, your question about how I was registering the IDependencyResolver made me think, because I had to use the IDependencyScope when registering my resolver with the ApiController. I am using a the standard Controller. So, registering it with the SetResolver() worked. Thanks! Commented Sep 26, 2012 at 19:30

3 Answers 3

2

I have to give props to Steven, since he steered me in the right direction, but basically, I was using a method to register my resolver with the ApiController rather than using the SetResolver method to register it with a standard controller.

Sign up to request clarification or add additional context in comments.

Comments

0

I had the same problem. I had installed Unity and then Unity.Mvc4. I uninstalled everything to do with Unity and reinstalled only Unity.Mvc4 and everything worked as advertised.

Comments

0

For this error in Unity go to the Global.asax and write the following code. Initialise the Bootstrapper.

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        Bootstrapper.Initialise();





    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.