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.
public static void RegisterApplicationServices(
Action<Type, Func<IServiceProvider, object>> register)
| parameter | description |
|---|---|
| register | 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());