I have a Singleton class that manages the connection to an external device. The idea of my application is that I need that external device to be presented all the time when the application is alive.
The Singleton has the following functionalities:
- Initialization, look for the device at the application startup time
- communicate with the external device, note that this can spread over multiple assemblies at multiple points.
- Close the connection when the application exits.
For the last part, I am thinking about putting the code inside Dispose
method of the singleton class, to guarantee that the resource is always cleanup upon closing. But since I am using a Singleton, and since singleton life span will only be terminated when the application exits, there is no need to explicitly close the connection in Dispose
since the connection will be close anyway.
So, the question is, should I put the close connection code inside Dispose
method?