Freigeben über


ServiceExtensions Class

Definition

Provides extension methods to retrieve proffered services synchronously from IServiceProvider and asynchronously from IAsyncServiceProvider.

public ref class ServiceExtensions abstract sealed
public static class ServiceExtensions
type ServiceExtensions = class
Public Module ServiceExtensions
Inheritance
ServiceExtensions

Remarks

Prefer IAsyncServiceProvider3 and this class over using IServiceProvider, IAsyncServiceProvider and IAsyncServiceProvider2 directly to avoid unexpected blocking RPC calls when casting the resulting service to a specific interface. The former also provide more consistent throwing behavior.

Methods

GetService<TService,TInterface>(IServiceProvider, Boolean)

Retrieves a proffered service synchronously, specifying whether to throw an exception if it could not be retrieved.

GetService<TService,TInterface>(IServiceProvider)

Retrieves a proffered service synchronously, throwing an exception if it could not be retrieved.

GetServiceAsync<TService,TInterface>(IAsyncServiceProvider, Boolean, CancellationToken)

Retrieves a proffered service asynchronously, specifying whether to throw an exception if it could not be retrieved.

GetServiceAsync<TService,TInterface>(IAsyncServiceProvider, Boolean)

Retrieves a proffered service asynchronously, specifying whether to throw an exception if it could not be retrieved.

GetServiceAsync<TService,TInterface>(IAsyncServiceProvider, CancellationToken)

Retrieves a proffered service asynchronously, throwing an exception if it could not be retrieved.

GetServiceAsync<TService,TInterface>(IAsyncServiceProvider)

Retrieves a proffered service asynchronously, throwing an exception if it could not be retrieved.

Applies to