【发布时间】:2021-02-12 03:19:39
【问题描述】:
我正在尝试注入两个在所有意义上都相同的单例 Cosmos 客户端,除了一个会改变其行为的属性,但我需要两者。这就是我在 Startup 中添加它们的方式:
services.AddSingleton(new CosmosClientBuilder(CosmosConnStr))
.Build());
services.AddSingleton(new CosmosClientBuilder(CosmosConnStr))
.WithBulkExecution(true)
.Build());
然后在我注入的类中:
public CosmosService(CosmosClient cosmosClient, CosmosClient bulkCosmosClient)
问题是如何区分一个和另一个?
【问题讨论】:
-
你能通过界面区分它们吗?将其中一个注册为 ICosmosClient,另一个注册为 IBulkCosmosClient
-
@user2363676 不幸的是,Cosmos 是一个外部库。
标签: c# .net-core dependency-injection asp.net-core-5.0