Skip to main content

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. Open the Startup.cs file and add the following line in the ConfigureServices method.
C#
You can reuse the same SearchClient for multiple indices, as SearchClient is thread-safe.
If you are using other clients such as the AnalyticsClient or InsightsClient you should also add them as singletons in the service provider.

Reusable clients in your controllers

To reuse the SearchClient instance in your controllers, add the following lines:
C#
Last modified on March 23, 2026