> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate Algolia with ASP.NET

> Learn how to add a reusable Algolia client to your ASP.NET application.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Performance" href="/doc/libraries/sdk/performance" />

## Inject a reusable client

To maintain optimal performance, reuse the client instance for every request.
To do this, inject the `SearchClient` as `singleton` in the [service provider](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.2).

Open the `Startup.cs` file and add the following line in the `ConfigureServices` method.

```cs C# icon=code theme={"system"}
public void ConfigureServices(IServiceCollection services)
{
    // ...
    services.AddSingleton<ISearchClient, SearchClient>();
    services.AddSingleton<ISearchClient>(new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));
    // ...
}
```

You can reuse the same `SearchClient` for multiple indices, as `SearchClient` is thread-safe.

<Info>
  If you are using other clients such as the `AnalyticsClient` or `InsightsClient` you should also add them as singletons in the service provider.
</Info>

## Reusable clients in your controllers

To reuse the `SearchClient` instance in your controllers, add the following lines:

```cs C# icon=code theme={"system"}
public class HomeController : Controller
{
    private readonly ISearchClient _searchClient;

    public HomeController(ISearchClient searchClient)
    {
        _searchClient = searchClient;
    }
}
```
