Skip to content

AngeloDotNet/AutomaticCustomKeyedServiceReg

Repository files navigation

Automatic Custom Keyed Service Registration

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.

Runtime keyed resolution

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)
    { }
}

About

This project demonstrates how to implement automatic custom keyed service registration using the `IServiceCollection` extension method.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages