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.

Community
  • 1
  • 1
DDiVita
  • 4,225
  • 5
  • 63
  • 117
  • 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`? – Steven Sep 26 '12 at 18:43
  • 1
    without any code, seems difficult to help you... – Cybermaxs Sep 26 '12 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! – DDiVita Sep 26 '12 at 19:30

3 Answers3

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.

Community
  • 1
  • 1
DDiVita
  • 4,225
  • 5
  • 63
  • 117
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.

Glenn Gordon
  • 1,266
  • 1
  • 14
  • 24
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();





    }
Debendra Dash
  • 5,334
  • 46
  • 38