ChatClientExtensions.GetRequiredService 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
GetRequiredService(IChatClient, Type, Object) |
Asks the IChatClient for an object of the specified type |
GetRequiredService<TService>(IChatClient, Object) |
Asks the IChatClient for an object of type |
GetRequiredService(IChatClient, Type, Object)
Asks the IChatClient for an object of the specified type serviceType
and throws an exception if one isn't available.
public static object GetRequiredService(this Microsoft.Extensions.AI.IChatClient client, Type serviceType, object? serviceKey = default);
static member GetRequiredService : Microsoft.Extensions.AI.IChatClient * Type * obj -> obj
<Extension()>
Public Function GetRequiredService (client As IChatClient, serviceType As Type, Optional serviceKey As Object = Nothing) As Object
Parameters
- client
- IChatClient
The client.
- serviceType
- Type
The type of object being requested.
- serviceKey
- Object
An optional key that can be used to help identify the target service.
Returns
The found object.
Exceptions
serviceType
is null
.
No service of the requested type for the specified key is available.
Remarks
The purpose of this method is to allow for the retrieval of services that are required to be provided by the IChatClient, including itself or any services it might be wrapping.
Applies to
GetRequiredService<TService>(IChatClient, Object)
Asks the IChatClient for an object of type TService
and throws an exception if one isn't available.
public static TService GetRequiredService<TService>(this Microsoft.Extensions.AI.IChatClient client, object? serviceKey = default);
static member GetRequiredService : Microsoft.Extensions.AI.IChatClient * obj -> 'Service
<Extension()>
Public Function GetRequiredService(Of TService) (client As IChatClient, Optional serviceKey As Object = Nothing) As TService
Type Parameters
- TService
The type of the object to be retrieved.
Parameters
- client
- IChatClient
The client.
- serviceKey
- Object
An optional key that can be used to help identify the target service.
Returns
The found object.
Exceptions
client
is null
.
No service of the requested type for the specified key is available.
Remarks
The purpose of this method is to allow for the retrieval of strongly typed services that are required to be provided by the IChatClient, including itself or any services it might be wrapping.