I have a below DI which will give me two different DatabaseClients.
_ = services.AddSingleton<IDbFactory>(x =>
{
var dbFactory = new DbFactory(x.GetRequiredService<IConfiguration>(), x.GetRequiredService<IKeyVaultManager>(), "**TestCluster1**");
return dbFactory;
});
_ = services.AddSingleton<IDbFactory>(x =>
{
var dbFactory = new DbFactory(x.GetRequiredService<IConfiguration>(), x.GetRequiredService<IKeyVaultManager>(), "**TestCluster2**");
return dbFactory;
});
Now I want to get specific client based on the basis of ClusterName as a key from the below constructor. Is there any way to achieve the same?
public class TestRepository : DbRepository<SomeEntity>, ITestRepository
{
public TestRepository(ILogger<DbRepository<SomeEntity>> logger, **IDbFactory clientFactory**)
: base(logger, clientFactory)
{
}
}