Dependency injection of multiple instances of same type in ASP.NET Core 2

后端 未结 4 756
醉梦人生
醉梦人生 2020-12-29 23:57

In ASP.NET Core 2 Web Api, I want to use dependency injection to inject httpClientA instance of HttpClient to ControllerA, and an inst

4条回答
  •  一个人的身影
    2020-12-30 00:52

    Another option is to

    • use an additional generic type parameter on the interface or a new interface implementing the non generic interface,
    • implement an adapter/interceptor class to add the marker type and then
    • use the generic type as “name”

    I’ve written an article with more details: Dependency Injection in .NET: A way to work around missing named registrations

提交回复
热议问题