Inject reusable clients
To maintain optimal performance, reuse theSearchClient
instance for all requests.
To do this, register it as a singleton in the service provider.
In the Startup.cs
file, add the following lines to the ConfigureServices
method:
C#
Program.cs
file:
C#
The
SearchClient
class is thread-safe, so you can reuse the same client with multiple indices.AnalyticsClient
and InsightsClient
, as singletons in the service provider.
Add reusable clients to controllers
To reuse theSearchClient
instance in your controllers, add the following lines:
C#