I created in simple ASP.NET Core web API, Let's say I have an interface as below:
public interface ITestService
{
string GetDate();
}
I am using Autofac to handle DI, for the above interface I have two registered types (TestService and TestComponent implementing ITestService) :
builder.RegisterType<TestService>().As<ITestService>().Keyed<ITestService>("service");
builder.RegisterType<TestComponent>().As<ITestService>().Keyed<ITestService>("component");
I know for a fact that I can register my type to use either of these bindings, and I know there is a way to get the proper type as discussed here:
var services = serviceProvider.GetServices<ITestService>();
var testComponent= services.First(o => o.GetType() == typeof(TestComponent));
Since I am using Autofac and registered my types using Keyed Services, how do I resolve the proper ITestService using IServiceProvider and the key I provided in my bindings ("service" or "component")?