# AspireAzureSearchExtensions Methods

- Package: [Aspire.Azure.Search.Documents](/reference/api/csharp/aspire.azure.search.documents.md)
- Type: [AspireAzureSearchExtensions](/reference/api/csharp/aspire.azure.search.documents/aspireazuresearchextensions.md)
- Kind: `Methods`
- Members: `2`

Provides extension methods for registering `Indexes.SearchIndexClient` as a singleton in the services provided by the `Hosting.IHostApplicationBuilder`.

## AddAzureSearchClient(IHostApplicationBuilder, string, Action<AzureSearchSettings>, Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>)

- Name: `AddAzureSearchClient(IHostApplicationBuilder, string, Action<AzureSearchSettings>, Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Components/Aspire.Azure.Search.Documents/AspireAzureSearchExtensions.cs#L40-L44)

Registers `Indexes.SearchIndexClient` as a singleton in the services provided by the `builder`.

```csharp
public static class AspireAzureSearchExtensions
{
    public static void AddAzureSearchClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<AzureSearchSettings>? configureSettings = null,
        Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>? configureClientBuilder = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<AzureSearchSettings>`) `optional`
  An optional method that can be used for customizing the [AzureSearchSettings](/reference/api/csharp/aspire.azure.search.documents/azuresearchsettings.md). It's invoked after the settings are read from the configuration.
- `configureClientBuilder` (`Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>`) `optional`
  An optional method that can be used for customizing the `Extensions.IAzureClientBuilder`2`.

## Remarks

Reads the configuration from "Aspire:Azure:Search:Documents" section.

## AddKeyedAzureSearchClient(IHostApplicationBuilder, string, Action<AzureSearchSettings>, Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>)

- Name: `AddKeyedAzureSearchClient(IHostApplicationBuilder, string, Action<AzureSearchSettings>, Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Components/Aspire.Azure.Search.Documents/AspireAzureSearchExtensions.cs#L60-L64)

Registers `Indexes.SearchIndexClient` as a singleton for given `name` in the services provided by the `builder`.

```csharp
public static class AspireAzureSearchExtensions
{
    public static void AddKeyedAzureSearchClient(
        this IHostApplicationBuilder builder,
        string name,
        Action<AzureSearchSettings>? configureSettings = null,
        Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>? configureClientBuilder = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `name` (`string`)
  The name of the component, which is used as the `ServiceDescriptor.ServiceKey` of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<AzureSearchSettings>`) `optional`
  An optional method that can be used for customizing the [AzureSearchSettings](/reference/api/csharp/aspire.azure.search.documents/azuresearchsettings.md). It's invoked after the settings are read from the configuration.
- `configureClientBuilder` (`Action<IAzureClientBuilder<SearchIndexClient, SearchClientOptions>>`) `optional`
  An optional method that can be used for customizing the `Extensions.IAzureClientBuilder`2`.

## Remarks

Reads the configuration from "Aspire:Azure:Search:Documents:{name}" section.
