Keyed services are useful when you have an interface/service with multiple implementations that you want to use in your app. What's more, you need to use each of those implementations in different places in your app. ☄️
Sample:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKeyedSingleton<INotificationService, SmsNotificationService>("sms");
builder.Services.AddKeyedSingleton<INotificationService, EmailNotificationService>("email");
builder.Services.AddKeyedSingleton<INotificationService, PushNotificationService>("push");
[ Article ] : https://andrewlock.net/exploring-the-dotnet-8-preview-keyed-services-dependency-injection-support〰️〰️〰️〰️〰️〰️
#DotNet #DotNetCore #AspNetCore #CSharp
@ProgrammingTip