Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TelegramBotClient disposable #845

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Make TelegramBotClient disposable #845

wants to merge 2 commits into from

Conversation

UselessToucan
Copy link

As far as I see, there is a HttpClient instance creation under the hood of a TelegramBotClient. Since HttpClient is IDisposable, I guess we should call _httpClient.Dispose() at some point.

@tuscen
Copy link
Member

tuscen commented Nov 10, 2019

This will make the client not DI-friendly since disposing of dependencies is a responsibility of a scope in a DI framework.

@karb0f0s
Copy link
Member

As mentioned in various resources - HttpClient should not be disposed after each request. But, it should be disposed at the end of its owner's lifecycle.

Summarizing:

  • we should not dispose user-provided HttpClient
  • we might not care about constructor-instantiated HttpClient when TelegramBotClient is a singleton object
  • we might consider disposing constructor-instantiated HttpClient when TelegramBotClient is a transient object
  • maybe we should encourage users to instantiate HttpClient for us (either as singleton or via HttpClientFactory) leaving only constructor which accepts both botToken and HttpClient.

@tuscen
Copy link
Member

tuscen commented Sep 24, 2020

@karb0f0s Good points. It’s a complicated case with no single best strategy and I still don’t know what to do here.

On one hand forcing people to pass HttpClient manually every time will make using the client quite inconvenient. On the other, though, it will make it clearer who owns the client and who’s responsible for it’s disposal.

GC.SuppressFinalize(this);
}

private void dispose()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename method in conformity with naming conventions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants