Simple Injector - No parameterless constructor defined for this object

后端 未结 2 2430
情深已故
情深已故 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 19:06

    The reason for getting this error is because you are missing the following registration (as explained in the MVC integration guide):

    DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
    

    MVC and Web API both have their own abstraction for resolving dependencies (both called 'dependency resolver'). Since you didn't set the resolver for MVC, MVC uses the default resolution mechanism for creating MVC controllers, but this requires controllers to have a default constructor.

    Calling DependencyResolver.SetResolver will solve the problem.

提交回复
热议问题