# ApplicationServicesContext class

Ambient access to the application services and the description of their composition.

The class knows about no particular DI container: the only integration type is IServiceProvider from the BCL. The service composition is described by [`RegisterApplicationServices`](./ApplicationServicesContext/RegisterApplicationServices.md), while lifetime and registration are chosen by the host.

[`Current`](./ApplicationServicesContext/Current.md) is meant only for places where constructor injection cannot reach: markup extensions, attached properties, converters, code-behind without a container. The library services themselves take dependencies through constructors and never touch the ambient context.

```csharp
public static class ApplicationServicesContext
```

## Public Members

| name | description |
| --- | --- |
| static [Current](ApplicationServicesContext/Current.md) { get; } | The current service provider, or `null` if it has not been set yet. |
| static [GetRequiredService&lt;T&gt;](ApplicationServicesContext/GetRequiredService.md)() | Returns the service, throwing InvalidOperationException when it is missing. |
| static [GetService&lt;T&gt;](ApplicationServicesContext/GetService.md)() | Returns the service, or `null` if it is not registered or the context has not been initialized yet. |
| static [RegisterApplicationServices](ApplicationServicesContext/RegisterApplicationServices.md)(…) | 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. |
| static [SetCurrent](ApplicationServicesContext/SetCurrent.md)(…) | Sets the current service provider. Called once at application startup. Passing `null` resets the context (used in tests). |

## See Also

* namespace [Eremex.AvaloniaUI.Controls.ApplicationServices](./index.md)

<!-- DO NOT EDIT: generated by xmldocmd for Eremex.Avalonia.Controls.ApplicationServices.dll -->
