make ElasticClient IDisposable
See original GitHub issueCurrently the ElasticClient is created, it is not possible to get rid of it. I would love to be able to do something like:
using (var settings) { settings.GlobalHeaders(new NameValueCollection { { "Authorization", $"Bearer {token}" } }; var client = new ElasticClient(settings); var results = client.DoSomething(); // return results; }
The problem with the ElasticClient is very static, it would be helpful in a MVC API Controller, we can switch “security context” of the connection.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ElasticClient Dispose - nest
The ElasticClient holds a single IConnection responsible for doing async and sync http calls. The IConnection does not reuse httprequests ...
Read more >Lifetimes | Elasticsearch .NET Clients [7.17]
If you are using an IOC/Dependency Injection container, it's always useful to know the best practices around the lifetime of your objects.
Read more >Step one - A simple Elastic Search Repository using NEST
By creating a fixture-class that inherits from IDisposable, you can put your setup in the constructor and your teardown in the Dispose-method.
Read more >HttpClient Creation and Disposal Internals ... - Steve Gordon
HttpClient is an example where the often blanket rule of making sure we always dispose of IDisposable objects breaks down.
Read more >C# IDisposable Example vs IAsyncDisposable
This tutorial will cover how to implement IDisposable in C#. Then, we will compare our C# IDisposable example with its async alternative. Let's ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @stevejgordon,
Okay, I tweak a little of my code and was lucky to have found the right syntax. This one works:
So if this per-call configuration does not keep anything in the ElasticClient. You are right, we can use a Singleton ElasticClient and just supply needed credentials at per-request basis.
Thank you for all your help.
@dliulabs The code in my comment above should work on your API call. It’s not
r => r.Authentication
butr => r.BasicAuthentication("username", "password")