This page documents an earlier version of the API client. For the latest version, see Performance.
Inject a reusable client
To maintain optimal performance, reuse the client instance for every request. To do this, inject theSearchClient
as singleton
in the service provider.
Open the Startup.cs
file and add the following line in the ConfigureServices
method.
C#
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 theSearchClient
instance in your controllers, add the following lines:
C#