I'm new to use Dependency Injection. When I use Dependency Injection to build my database helper to connect the database. I inject the parameter in Program.cs. Just like this:
builder.Services.AddSingleton<IElasticSearchHelper, ElasticSearchHelper>(x =>
new ElasticSearchHelper(url,user, password));
And I want to make another helper to connect another database to do something different. If I don't use injection. I will do like this.
ElasticSearchHelper eshelper_1 = new ElasticSearchHelper(url_1,user, password);
ElasticSearchHelper eshelper_2 = new ElasticSearchHelper(url_2,user, password);
But I'm not sure how to use Dependency Injection to make like this.
And I think how to solve this. Maybe I create another implementation to inject.
builder.Services.AddSingleton<IElasticSearchHelper, ElasticSearchHelper>(x =>
new ElasticSearchHelper(url_1,user, password));
builder.Services.AddSingleton<IElasticSearchHelper, ElasticSearchHelper_01>(x =>
new ElasticSearchHelper_01(url_2,user, password));
or maybe I should create an IElasticSearchFactoryHelper
to include multiple ElasticSearchHelper
instances?