ServiceRegistry
Contract for service registry modules that configure an IServiceCollection. A type implementing it is added through AddService<T>, which constructs the module and calls ConfigureService.
Implementations need a public parameterless constructor, because AddService<T> constructs the module directly rather than resolving it from the container.
ConfigureService
Adds the module's registrations to the provided IServiceCollection. AddService<T> calls this after constructing the module, and application code can call it directly when it already owns an instance.
The collection passed in is the application's live one, not a copy, so registrations made here are visible to the rest of startup and there is nothing to return. Do not resolve services or perform runtime work here; this method should only describe registrations.
using AlmightyShogun.Utils;
using Microsoft.Extensions.DependencyInjection;
builder.Services.AddService<NotificationsRegistry>();using AlmightyShogun.Utils;
using Microsoft.Extensions.DependencyInjection;
public sealed class NotificationsRegistry : IServiceRegistry
{
public void ConfigureService(IServiceCollection serviceCollection)
=> serviceCollection.AddSingleton<NotificationFormatter>();
}public sealed class NotificationFormatter
{
public string Format(string message) => $"Notification: {message}";
}Type signature
public void ConfigureService(IServiceCollection serviceCollection);