AddService
Constructs a service registry module and calls its ConfigureService method, so a group of related registrations can live in one reusable type instead of being spread across startup code.
The module type must implement IServiceRegistry and have a public parameterless constructor. It is created directly rather than resolved from the container, so it cannot take constructor dependencies.
Usage
csharp
using AlmightyShogun.Utils;
using Microsoft.Extensions.DependencyInjection;
builder.Services.AddService<NotificationsRegistry>();csharp
using AlmightyShogun.Utils;
using Microsoft.Extensions.DependencyInjection;
public sealed class NotificationsRegistry : IServiceRegistry
{
public void ConfigureService(IServiceCollection serviceCollection)
=> serviceCollection
.AddSingleton<NotificationFormatter>()
.AddScoped<INotificationSender, EmailNotificationSender>();
}Returns
The sameIServiceCollection instance, with the module's registrations applied.Type signature
csharp
public IServiceCollection AddService<T>() where T : IServiceRegistry, new();