This project demonstrates how to implement automatic custom keyed service registration using the IServiceCollection extension method.
The example includes a simple implementation of a service that can be registered with a custom key and retrieved later.
var smtp = provider.GetRequiredKeyedService<IEmailSender>("smtp");
var ses = provider.GetRequiredKeyedService<IEmailSender>("ses");With injection:
using Microsoft.Extensions.DependencyInjection;
public class NotificationService
{
public NotificationService([FromKeyedServices("smtp")] IEmailSender emailSender)
{ }
}