Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Add/implement IDisposable on ClientEntity #130

Closed
justdmitry opened this issue Apr 13, 2017 · 3 comments
Closed

Add/implement IDisposable on ClientEntity #130

justdmitry opened this issue Apr 13, 2017 · 3 comments
Labels

Comments

@justdmitry
Copy link

ClientEntity (and it successors) have public CloseAsync method, which indicates that "good practice" is to close each client/entity after use.

For many years, this is known as Dispose pattern, and special IDisposable interface and using language construct are created for this scenario.

Please, add IDisposable interface to ClientEntity class.

@jtaubensee
Copy link
Contributor

@justdmitry - So this is an interesting question. While in most cases it is proper to implement the IDisposible class, we don't necessarily want to encourage the using syntax. For example:

using (var qClient = new QueueClient())
{
    qClient.SendAsync(new Message(Encoding.UTF8.GetBytes("Hello")));
}

In most cases, the QueueClient is long-lived, and a Windows service would create a single client and use it throughout the application.

What we ultimately want to avoid, is customers using the above example (using statement) repeatedly throughout their application. Under the covers this is creating a connection, sending a single message, and then closing the connection, which is a heavy series of operations.

@justdmitry
Copy link
Author

Understand.

That's looks like HttpClient per call / singleton issue...

Do you recommend (for web app) register it as a singleton for whole app lifetime? Does QueueClient/TopicClient are (or planned to be in RTM) thread-safe?

@jtaubensee
Copy link
Contributor

@justdmitry - Yep, its basically the same as HttpClient; that is a good comparison.

The clients should be thread safe.

You've actually brought up a good point (which we were hoping to address later, but has some relevance here). See #134.

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

No branches or pull requests

2 participants