How to use Unity MVC & Unity WebAPI in the same ASP.Net MVC project -


i'm trying add webapi existing asp.net mvc project , question regarding unity:

before unitymvc alone, project had in app_start folder, class unityconfig following code:

container.registertype<iunitofwork, unitofwork>(new perrequestlifetimemanager()); container.registertype<idatacontext, tfe_schemacontext>(new perrequestlifetimemanager());  container.registertype<iprintjobservice, printjobservice>(new perrequestlifetimemanager()); container.registertype<irepository<print_job>, repository<print_job>>(new perrequestlifetimemanager()); 

to use webapi, added unitywebapi via nuget , action added unitymvcactivator class in app_start folder.

the following error displayed when execute project: "the type unity.webapi.unitydependencyresolver not appear implement microsoft.practices.servicelocation.iservicelocator. parameter name: commonservicelocator".

i found different examples of code using bootstrapper class without using unityconfig class or unitymvcactivator.

in bootrstrapper class, registration of types this:

container.registertype<iproductservices, productservices>().registertype<unitofwork>(new hierarchicallifetimemanager()); 

i'm little bit lost this, please me understand , fix error.

it seems using wrong or outdated nuget packages. try use unity's official packages instead. therefore remove packages related unity , add following packages in package manager console:

install-package unity.mvc install-package unity.aspnet.webapi 

now have 1 unity container in project works mvc , webapi.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -