Simple Injector - No parameterless constructor defined for this object

后端 未结 2 2433
情深已故
情深已故 2021-02-20 18:10

I have a new MVC Web Project which i am usin MVC and WebApi in. I have setup Simple Injector (version 2.5.2 from nuGet) using the following code in my global file



        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 18:53

    For Web API Projects, the SetResolver method described above will compile but when the application is run, you'll get an ArgumentException error: "Additional information: The type SimpleInjector.Integration.WebApi.SimpleInjectorWebApiDependencyResolver does not appear to implement Microsoft.Practices.ServiceLocation.IServiceLocator."

    You'll resolved this issue by setting the DependencyResolver to a SimpleInjectorWebApiDependencyResolver and pass in your container, like below.

    GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
    

提交回复
热议问题