ASP.NET Core Dependency Injection with Multiple Constructors

后端 未结 5 2073
独厮守ぢ
独厮守ぢ 2020-12-06 04:33

I have a tag helper with multiple constructors in my ASP.NET Core application. This causes the following error at runtime when ASP.NET 5 tries to resolve the type:

5条回答
  •  猫巷女王i
    2020-12-06 04:42

    ASP.NET Core 1.0 Answer

    The other answers are still true for parameter-less constructors i.e. if you have a class with a parameter-less constructor and a constructor with arguments, the exception in the question will be thrown.

    If you have two constructors with arguments, the behaviour is to use the first matching constructor where the parameters are known. You can look at the source code for the ConstructorMatcher class for details here.

提交回复
热议问题