Click or drag to resize

ServiceHelper.GetService<T> Method (IServiceProvider, Boolean)

Gets a service from a given service provider.

Namespace:  AGI.Foundation.Infrastructure
Assembly:  AGI.Foundation.Core (in AGI.Foundation.Core.dll) Version: 25.1.421.0 (25.1.421.0)
Syntax
public static T GetService<T>(
	IServiceProvider serviceProvider,
	bool throwIfNotAvailable
)
where T : class

Parameters

serviceProvider
Type: System.IServiceProvider
The service provider from which to obtain the service.
throwIfNotAvailable
Type: System.Boolean
true if this method should throw a ServiceNotAvailableException if the requested service is not available from the service provider, or false if this method should simply return null if the service does not exist.

Type Parameters

T
The type of service to obtain.

Return Value

Type: T
The requested service.
Exceptions
ExceptionCondition
ArgumentNullException Thrown when the serviceProvider is null.
ServiceNotAvailableException Thrown when throwIfNotAvailable is true, and the requested service is not available from the service provider.
See Also