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, while lifetime and registration are chosen by the host.
Current 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.
Public Members¶
| name | description |
|---|---|
| static Current { get; } | The current service provider, or null if it has not been set yet. |
| static GetRequiredService<T>() | Returns the service, throwing InvalidOperationException when it is missing. |
| static GetService<T>() | Returns the service, or null if it is not registered or the context has not been initialized yet. |
| static RegisterApplicationServices(…) | 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(…) | Sets the current service provider. Called once at application startup. Passing null resets the context (used in tests). |