-
Notifications
You must be signed in to change notification settings - Fork 848
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-aiMicrosoft.Extensions.AI librariesMicrosoft.Extensions.AI libraries
Description
Background and motivation
When working with DI containers, a common method to use is GetRequiredService when you expect the service to be provided by the DI container. In our code alone we have thousands of references to it:
However IChatClient only has object? GetService and TService? GetService<TService>.
API Proposal
namespace Microsoft.Extensions.AI;
public static class ChatClientExtensions
{
public static TService GetRequiredService<TService>(this IChatClient client, object? serviceKey = null)
}API Usage
// most of my app is written agnostic of the service it is talking to
IChatClient client = ...;
// this part of my app needs to drop down to a specific client type to get access to its specific functionality
var azureAIClient = client.GetRequiredService<AzureAIInferenceChatClient>();Alternative Designs
No response
Risks
No response
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-aiMicrosoft.Extensions.AI librariesMicrosoft.Extensions.AI libraries
