ServiceExtensions.GetService Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetService<TService,TInterface>(IServiceProvider) |
Gets a service interface from a service provider. |
GetService<TService,TInterface>(IServiceProvider, Boolean) |
Gets a service interface from a service provider. |
GetService<TService,TInterface>(IServiceProvider)
Gets a service interface from a service provider.
public:
generic <typename TService, typename TInterface>
where TInterface : class[System::Runtime::CompilerServices::Extension]
static TInterface GetService(IServiceProvider ^ sp);
public static TInterface GetService<TService,TInterface> (this IServiceProvider sp) where TInterface : class;
static member GetService : IServiceProvider -> 'Interface (requires 'Interface : null)
<Extension()>
Public Function GetService(Of TService, TInterface) (sp As IServiceProvider) As TInterface
Type Parameters
- TService
The service type
- TInterface
The interface type
Parameters
The service provider
Returns
The requested service interface. Never null.
Exceptions
Either the service could not be acquired, or the service does not support the requested interface.
Applies to
GetService<TService,TInterface>(IServiceProvider, Boolean)
Gets a service interface from a service provider.
public static TInterface? GetService<TService,TInterface> (this IServiceProvider sp, bool throwOnFailure = true) where TInterface : class;
static member GetService : IServiceProvider * bool -> 'Interface (requires 'Interface : null)
<Extension()>
Public Function GetService(Of TService, TInterface) (sp As IServiceProvider, Optional throwOnFailure As Boolean = true) As TInterface
Type Parameters
- TService
The service type
- TInterface
The interface type
Parameters
The service provider
- throwOnFailure
- Boolean
Determines how a failure to get the requested service interface is handled. If true, an exception is thrown; if false, null is returned.
Returns
The requested service interface, if it could be obtained; otherwise null
if throwOnFailure
is false
.
Exceptions
Either the service could not be acquired, or the service does not support the requested interface.