# 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.

```csharp
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:

```csharp
ApplicationServicesContext.RegisterApplicationServices(
    (type, factory) => services.AddSingleton(type, sp => factory(sp)));
```

Autofac:

```csharp
ApplicationServicesContext.RegisterApplicationServices(
    (type, factory) => builder.Register(c => factory(c.Resolve<IServiceProvider>())).As(type).SingleInstance());
```

## See Also

* class [ApplicationServicesContext](../ApplicationServicesContext.md)
* namespace [Eremex.AvaloniaUI.Controls.ApplicationServices](../index.md)

<!-- DO NOT EDIT: generated by xmldocmd for Eremex.Avalonia.Controls.ApplicationServices.dll -->
