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

# Performance in ASP.NET apps

> Optimize performance of the Algolia C#/.NET API clients for ASP.NET applications.

## Inject reusable clients

To maintain optimal performance, reuse the `SearchClient` instance for all requests.
To do this, register it as a singleton in the [service provider](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection).

In the `Startup.cs` file, add the following lines to the `ConfigureServices` method:

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

For ASP.NET [minimal APIs](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/overview),
add the following line to your `Program.cs` file:

```cs C# icon=code theme={"system"}
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSingleton<ISearchClient>(new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));
```

<Tip>
  The `SearchClient` class is thread-safe, so you can reuse the same client with multiple indices.
</Tip>

Also register other clients, such as `AnalyticsClient` and `InsightsClient`, as singletons in the service provider.

## Add reusable clients to 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;
    }
}
```
