Skip to content

Conversation

@m-nash
Copy link
Member

@m-nash m-nash commented Oct 28, 2025

Initial prototype to support Microsoft.Extensions.Configuration and Microsoft.Extensions.DependencyInjection

Sample usage with configuration only

        ConfigurationManager config = new();
        config.AddJsonFile("appsettings.json", optional: false);
        config.AddEnvironmentVariables();

        ClientConnection openAIConnection = config.GetConnection("OpenAIClient");
        ClientConnection azureOpenAIConnection = config.GetAzureConnection("AzureOpenAIClient");

        ChatClient openAIChatClient = openAIConnection.CreateChatClient();
        ChatClient azureOpenAIChatClient = azureOpenAIConnection.CreateChatClient();

        Console.WriteLine(openAIChatClient.CompleteChat("Hello world!").Value.Content[0].Text);
        Console.WriteLine(azureOpenAIChatClient.CompleteChat("Hello world!").Value.Content[0].Text);

Sample usage with dependency injection

        IHost host = Host.CreateDefaultBuilder()
            .AddKeyedOpenAIChatClient("oai", "OpenAIClient")
            .AddKeyedOpenAIChatClient("aoai", "AzureOpenAIClient")
            .Build();

        ChatClient openAIChatClient = host.Services.GetRequiredKeyedService<ChatClient>("oai");
        ChatClient azureOpenAIChatClient = host.Services.GetRequiredKeyedService<ChatClient>("aoai");

        Console.WriteLine(openAIChatClient.CompleteChat("Hello world!").Value.Content[0].Text);
        Console.WriteLine(azureOpenAIChatClient.CompleteChat("Hello world!").Value.Content[0].Text);

@github-actions
Copy link

github-actions bot commented Oct 28, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

Azure.Core
Azure.Identity
Azure.ResourceManager
System.ClientModel

}
public static partial class ConfigurationManagerExtensions
{
public static System.ClientModel.Primitives.ClientConnection GetConnection(this Microsoft.Extensions.Configuration.IConfigurationManager configuration, string sectionName) { throw null; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these apis are in SCM, should these be just static Create methods on ClientConnection, or maybe even ClientConnection ctor? This way we don't need to add a new type (the config extensions)

/// <param name="configuration"></param>
/// <param name="sectionName"></param>
/// <returns></returns>
public static ClientConnection GetConnection(this IConfigurationManager configuration, string sectionName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we dont need an optional parameter called "format" (or something like that). This would allow us to add support for all the combinations in aspire. Unless we are fine with probing all the formats.

/// <param name="configuration"></param>
/// <param name="sectionName"></param>
/// <returns></returns>
public static ClientConnection GetAzureConnection(this IConfigurationManager configuration, string sectionName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should not give it a nice name: GetClientConnection. This method will work with both Azure and non-Azure scenarios. I even wonder if we could call the SCM variant of the method the same and use the new C# attribute (overload priority) to resolve ambiguity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core Azure.Identity Mgmt This issue is related to a management package.

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

4 participants