ASP.NET Core Dependency Injection with Multiple Constructors

后端 未结 5 2070
独厮守ぢ
独厮守ぢ 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条回答
  •  佛祖请我去吃肉
    2020-12-06 04:45

    ASP.NET Core 2.1 and higher

    You can use ActivatorUtilitiesConstructorAttribute on the constructor which you want to be used in DI:

    [ActivatorUtilitiesConstructor]
    public MyClass(ICustomDependency d)
    {
    }
    

提交回复
热议问题