Best practice in using elasticClient with authentication in .net core

Hey, we are trying to create a POC for using Elasticsearch in one of our features.
I couldn't find a proper example of how to use Elasticsearch in .netcore DI.
what is the best life time for elasticClient?
I manage to find this tutorial .Net 6 WebAPI - Intro to ElasticSearch - Step by Step #aspnetcore - DEV Community
but when i'm trying to implement it, the IDE (VS22) is showing me this error:

this is the code:

public static void AddElasticsearch(this IServiceCollection services, IConfiguration configuration)
        {
            IElasticConnectionSettingsProvider elasticConnectionSettingsProvider = new ElasticConnectionSettingsProvider(configuration);
            ElasticConnectionSettings elasticConnectionSettings = elasticConnectionSettingsProvider.GetElasticConnectionSettings();
            Uri uri = new Uri(elasticConnectionSettings.Uri);
            ConnectionSettings settings = new ConnectionSettings(uri)
                            .BasicAuthentication(elasticConnectionSettings.UserName, elasticConnectionSettings.Password);
            IElasticClient client = new ElasticClient(settings);
            services.AddSingleton(client);
        }

i'm using Nest 7.10.0, tried also newer versions with the same results.

am I missing something?
Thanks,
Or

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.