Unity not detecting automatically webapi controllers

Dec 16, 2013 at 12:10 PM
Running in an Azure Worker Role and and OWin hosted WebApi using WebAPI 2 (MVC 5)

I have to add my controllers by hand, is it normal as there is this comment in the configuration file added by the nuget Unity.WebAPI package

"// register all your components with the container here
        // it is NOT necessary to register your controllers"
I also noticed many exceptions catched without trace on startup, I am suspecting a compatibility issue with last WebAPI code ???
Editor
Dec 17, 2013 at 5:22 AM
I notice that the package Unity.AspNet.WebApi references System.Web.Http 4.0. Try adding a binding redirect to System.Web.Http 5.0:
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
...
    </assemblyBinding>
  </runtime>

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Dec 17, 2013 at 8:06 AM
I already done it, moreover I noticed main ResolutionFailedException in the starttime on some methods from refrence assemblies.
I will try to come back and give the exact name.
Dec 23, 2013 at 4:37 PM
CSADNT, have you found a resolution?
Dec 23, 2013 at 6:08 PM
Ok, I think I got it.

I had started with the SPA template, and added Unity 3.0 plus Unity bootstrapper for ASP.NET Web API. The AccountController code the template adds, comes with two public constructors.

Unity starts with matching the most specific constructor if no InjectionConstructor is provided, by looking at the constructor argument list, if multiple ctors exist, it will match the one with the longest argument list (hence not the default ctor) and will not be able to instantiate the controller.

Resolution is (depending on the testing approach) either provide resolution logic for UserManager<IdentityUser> and ISecureDataFormat<> types or make the non-default constructor on the template generated AccountController type as not public.
Dec 23, 2013 at 10:24 PM
Ok thanks