Table of Contents

ServiceCollectionExtensions Class

Definition

Namespace
Savvyio.Extensions.DependencyInjection
Assemblies
Savvyio.Extensions.DependencyInjection.dll
Source
src/Savvyio.Extensions.DependencyInjection/ServiceCollectionExtensions.cs

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
object
ServiceCollectionExtensions

Examples

Register Savvy I/O in the DI container with AddSavvyIO, add the handler descriptor, a service locator, configured options, a data source, and a marshaller — all through IServiceCollection extension methods.

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

namespace ExampleApp;

public static class ServiceRegistration
{
    public static IServiceCollection AddApplicationServices(this IServiceCollection services)
    {
        services.AddSavvyIO(options => options.EnableHandlerServicesDescriptor());
        services.AddHandlerServicesDescriptor();
        services.AddServiceLocator();
        services.AddConfiguredOptions<SavvyioOptions>(_ => { });
        services.AddDataSource<AppDataSource>();
        services.AddMarshaller<AppMarshaller>(p => new AppMarshaller());
        return services;
    }
}

public sealed class AppDataSource : IDataSource { }

public sealed class AppMarshaller : IMarshaller
{
    public Stream Serialize<TValue>(TValue value) => Stream.Null;
    public Stream Serialize(object value, System.Type inputType) => Stream.Null;
    public TValue Deserialize<TValue>(Stream data) => default!;
    public object Deserialize(Stream data, System.Type returnType) => null!;
}

Methods

Name Description
AddConfiguredOptions<TOptions>(IServiceCollection, Action<TOptions>)

Registers the specified setup as a triple-configuration for both compatibility with (and outside the confines of) Microsoft Dependency Injection e.g., IOptions<TOptions>, Action<TOptions> and TOptions.

AddDataSource<TService>(IServiceCollection, Action<ServiceOptions>)

Adds an implementation of IDataSource to the specified IServiceCollection.

AddHandlerServicesDescriptor(IServiceCollection)

Adds the HandlerServicesDescriptor to the specified IServiceCollection if it was allowed included from AddSavvyIO(IServiceCollection, Action<SavvyioDependencyInjectionOptions>).

AddMarshaller<TService>(IServiceCollection, Action<ServiceOptions>)

Adds an implementation of IMarshaller to the specified IServiceCollection.

AddMarshaller<TService>(IServiceCollection, Func<IServiceProvider, TService>, Action<ServiceOptions>)

Adds an implementation of IMarshaller to the specified IServiceCollection.

AddSavvyIO(IServiceCollection, Action<SavvyioDependencyInjectionOptions>)

Adds Savvy I/O related dispatcher- and handler- types to the specified IServiceCollection.

AddServiceLocator(IServiceCollection, Action<ServiceLocatorOptions>)

Adds Savvy I/O service locator used to resolve necessary dependencies.