From 757feae5fd3812329e3db88e8fae2c6e630452c7 Mon Sep 17 00:00:00 2001 From: tg-msft Date: Mon, 8 Jun 2020 18:09:42 -0700 Subject: [PATCH 1/2] Adding SearchClientBuilderExtensions Fixes #10848 --- .../Azure.Search.Documents.netstandard2.0.cs | 10 ++ .../src/SearchClientBuilderExtensions.cs | 110 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 sdk/search/Azure.Search.Documents/src/SearchClientBuilderExtensions.cs diff --git a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs index d76aa984fdc8..96826ecf2fdf 100644 --- a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs +++ b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs @@ -2049,3 +2049,13 @@ public ValueFacetResult(long count, T value) { } public T Value { get { throw null; } } } } +namespace Microsoft.Extensions.Azure +{ + public static partial class SearchClientBuilderExtensions + { + public static Azure.Core.Extensions.IAzureClientBuilder AddSearchClient(this TBuilder builder, System.Uri endpoint, string indexName, Azure.AzureKeyCredential credential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; } + public static Azure.Core.Extensions.IAzureClientBuilder AddSearchClient(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration { throw null; } + public static Azure.Core.Extensions.IAzureClientBuilder AddSearchIndexClient(this TBuilder builder, System.Uri endpoint, Azure.AzureKeyCredential credential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; } + public static Azure.Core.Extensions.IAzureClientBuilder AddSearchIndexClient(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration { throw null; } + } +} diff --git a/sdk/search/Azure.Search.Documents/src/SearchClientBuilderExtensions.cs b/sdk/search/Azure.Search.Documents/src/SearchClientBuilderExtensions.cs new file mode 100644 index 000000000000..3d4154d11761 --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/SearchClientBuilderExtensions.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure; +using Azure.Core.Extensions; +using Azure.Search.Documents; +using Azure.Search.Documents.Indexes; + +namespace Microsoft.Extensions.Azure +{ + /// + /// Extension methods to add to the Azure client + /// builder. + /// + public static class SearchClientBuilderExtensions + { + /// + /// Registers a instance with the provided + /// , , and + /// . + /// + /// Type of the client factory builder. + /// The client factory builder. + /// + /// Required. The URI endpoint of the Search Service. This is likely + /// to be similar to "https://{search_service}.search.windows.net". + /// The URI must use HTTPS. + /// + /// + /// Required. The name of the Search Index. + /// + /// + /// Required. The API key credential used to authenticate requests + /// against the search service. You need to use an admin key to + /// modify the documents in a Search Index. See + /// + /// for more information about API keys in Azure Cognitive Search. + /// + /// An Azure client builder. + public static IAzureClientBuilder AddSearchClient( + this TBuilder builder, + Uri endpoint, + string indexName, + AzureKeyCredential credential) + where TBuilder : IAzureClientFactoryBuilder => + builder.RegisterClientFactory( + options => new SearchClient(endpoint, indexName, credential, options)); + + /// + /// Registers a instance with connection + /// options loaded from the provided + /// instance. + /// + /// Type of the client factory builder. + /// Type of the configuration. + /// The client factory builder. + /// The client configuration. + /// An Azure client builder. + public static IAzureClientBuilder AddSearchClient( + this TBuilder builder, + TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration => + builder.RegisterClientFactory(configuration); + + + /// + /// Registers a instance with the + /// provided and . + /// + /// Type of the client factory builder. + /// The client factory builder. + /// + /// Required. The URI endpoint of the Search Service. This is likely + /// to be similar to "https://{search_service}.search.windows.net". + /// The URI must use HTTPS. + /// + /// + /// Required. The API key credential used to authenticate requests + /// against the search service. You need to use an admin key to + /// modify the documents in a Search Index. See + /// + /// for more information about API keys in Azure Cognitive Search. + /// + /// An Azure client builder. + public static IAzureClientBuilder AddSearchIndexClient( + this TBuilder builder, + Uri endpoint, + AzureKeyCredential credential) + where TBuilder : IAzureClientFactoryBuilder => + builder.RegisterClientFactory( + options => new SearchIndexClient(endpoint, credential, options)); + + /// + /// Registers a instance with connection + /// options loaded from the provided + /// instance. + /// + /// Type of the client factory builder. + /// Type of the configuration. + /// The client factory builder. + /// The client configuration. + /// An Azure client builder. + public static IAzureClientBuilder AddSearchIndexClient( + this TBuilder builder, + TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration => + builder.RegisterClientFactory(configuration); + } +} From a1c1be4a1fd305be876ac96f9fb78f95bd65f5ae Mon Sep 17 00:00:00 2001 From: tg-msft Date: Tue, 9 Jun 2020 09:05:17 -0700 Subject: [PATCH 2/2] Updating Changelog --- sdk/search/Azure.Search.Documents/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/search/Azure.Search.Documents/CHANGELOG.md b/sdk/search/Azure.Search.Documents/CHANGELOG.md index d20d103a4705..1799d2bb3d5c 100644 --- a/sdk/search/Azure.Search.Documents/CHANGELOG.md +++ b/sdk/search/Azure.Search.Documents/CHANGELOG.md @@ -1,9 +1,10 @@ # Release History -## 1.0.0-preview.4 (Unreleased) +## 1.0.0-preview.4 (2020-05-09) ### Added +- Added `SearchClientBuilderExtensions` to integrate with ASP.NET Core. - Added `SearchModelFactory` to mock output model types. ### Breaking Changes