Skip to content

ApplicationServicesContext.RegisterApplicationServices method

Describes the application service composition without knowing anything about a particular DI container. The host receives service type / factory pairs and decides how to register them and with which lifetime.

Namespace: Eremex.AvaloniaUI.Controls.ApplicationServices
Assembly: Eremex.Avalonia.Controls.ApplicationServices.dll
NuGet Package: Eremex.Avalonia.Controls.ApplicationServices

Declaration

public static void RegisterApplicationServices(
    Action<Type, Func<IServiceProvider, object>> register)

Parameters

name type description
register Action<Type, Func<IServiceProvider, object>> Called once per service with the service type and a factory that creates it from an IServiceProvider. Register each pair with the container of your choice; the services are designed to be singletons.

Exceptions

exception condition
ArgumentNullException register is null.

Examples

Microsoft.Extensions.DependencyInjection:

ApplicationServicesContext.RegisterApplicationServices(
    (type, factory) => services.AddSingleton(type, sp => factory(sp)));

Autofac:

ApplicationServicesContext.RegisterApplicationServices(
    (type, factory) => builder.Register(c => factory(c.Resolve<IServiceProvider>())).As(type).SingleInstance());

See Also