-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ASP.NET Core Integration for Text analytics (#10984)
* add client builder extensions * changelog
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClientBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure; | ||
using Azure.AI.TextAnalytics; | ||
using Azure.Core.Extensions; | ||
|
||
namespace Microsoft.Extensions.Azure | ||
{ | ||
/// <summary> | ||
/// Extension methods to add <see cref="TextAnalyticsClient"/> client to clients builder. | ||
/// </summary> | ||
public static class TextAnalyticsClientBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Registers a <see cref="TextAnalyticsClient"/> instance with the provided <paramref name="endpoint"/>. | ||
/// </summary> | ||
public static IAzureClientBuilder<TextAnalyticsClient, TextAnalyticsClientOptions> AddTextAnalyticsClient<TBuilder>(this TBuilder builder, Uri endpoint) | ||
where TBuilder : IAzureClientFactoryBuilderWithCredential | ||
{ | ||
return builder.RegisterClientFactory<TextAnalyticsClient, TextAnalyticsClientOptions>((options, credential) => new TextAnalyticsClient(endpoint, credential, options)); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a <see cref="TextAnalyticsClient"/> instance with the provided <paramref name="endpoint"/> and <paramref name="credential"/>. | ||
/// </summary> | ||
public static IAzureClientBuilder<TextAnalyticsClient, TextAnalyticsClientOptions> AddTextAnalyticsClient<TBuilder>(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) | ||
where TBuilder : IAzureClientFactoryBuilder | ||
{ | ||
return builder.RegisterClientFactory<TextAnalyticsClient, TextAnalyticsClientOptions>(options => new TextAnalyticsClient(endpoint, credential, options)); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a <see cref="TextAnalyticsClient"/> instance with connection options loaded from the provided <paramref name="configuration"/> instance. | ||
/// </summary> | ||
public static IAzureClientBuilder<TextAnalyticsClient, TextAnalyticsClientOptions> AddTextAnalyticsClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) | ||
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration> | ||
{ | ||
return builder.RegisterClientFactory<TextAnalyticsClient, TextAnalyticsClientOptions>(configuration); | ||
} | ||
} | ||
} |