Table of Contents

Class ServiceProviderExtensions

Namespace
Savvyio.Extensions.DependencyInjection
Assembly
Savvyio.Extensions.DependencyInjection.dll

Extension methods for the IServiceProvider interface.

public static class ServiceProviderExtensions
Inheritance
ServiceProviderExtensions

Examples

WriteHandlerDiscoveriesToLog<TCategoryName> resolves IHandlerServicesDescriptor from the service provider and writes the handler discovery report to the named logger. Call it at startup after building the service provider.

using System;
using Microsoft.Extensions.DependencyInjection;
using Savvyio;
using Savvyio.Extensions.DependencyInjection;
using Savvyio.Handlers;

namespace ExampleApp;

public static class DependencyInjectionDiagnostics
{
    public static IServiceProvider BuildProvider()
    {
        var services = new ServiceCollection();
        services.AddSavvyIO(options => options.EnableHandlerServicesDescriptor());
        services.AddHandlerServicesDescriptor();
        return services.BuildServiceProvider();
    }

    public static void LogRegisteredHandlers(IServiceProvider provider)
    {
        provider.WriteHandlerDiscoveriesToLog<HandlerDiscoveryLogCategory>();
    }
}

public sealed class HandlerDiscoveryLogCategory { }

Methods

WriteHandlerDiscoveriesToLog<TCategoryName>(IServiceProvider)

Writes the handler discoveries to ILogger<TCategoryName> with Information.

public static void WriteHandlerDiscoveriesToLog<TCategoryName>(this IServiceProvider provider)

Parameters

provider IServiceProvider

The service provider used to resolve services.

Type Parameters

TCategoryName

The type used to categorize the log messages.