Skip to content

Commit

Permalink
Add ASP.NET Core Integration for Text analytics (#10984)
Browse files Browse the repository at this point in the history
* add client builder extensions

* changelog
  • Loading branch information
maririos authored Apr 2, 2020
1 parent 5e5d03a commit 286017b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Added
- Refactor common properties from `DetectLanguageInput` and `TextDocumentInput` into it's own type `TextAnalyticsInput`.
- Mock support for the Text Analytics client with respective samples.
- Integration for ASP.NET Core.

## 1.0.0-preview.3 (2020-03-10)
### Breaking changes
Expand Down
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);
}
}
}

0 comments on commit 286017b

Please sign in to comment.