Not sure where this stands, but I’m running into the need for this. I’m testing some failure scenarios.
When I have a naive static readonly connection, if the connection ever dies, the object is disposed and can’t be used anymore. The API can’t recover and must be restarted.
So, I have to make it mutable, put locking around it, hide it in a class, etc. But I do not see a way to directly ask the connection object if it is disposed.
There appear to be two ways to know if the connection is good. #1 subscribing to one of the events exposed by the connection. (I think it’s the Closed event, but not sure because some are raised even though the connection will retry.) #2 Just trying an operation and catching an ObjectDisposedException.
Were it not for the expense, I would probably just create a connection on every request to make sure I have a live one.
So yeah, some sort of connection pooling / flyweight would be a great help here, especially for stateless connections, where the use case is just to make sure it’s up before processing an operation.