I have a windows service, which contains a singleton which in turn uses some loggers, message queue listeners and so on. Those classes implements IDisposable
. S
If a type will be returned from a factory that will sometimes need to be cleaned up when the caller is done with them, the type should implement IDisposable
. If a particular factory returns a shared singleton object that doesn't actually need any resources, the object returned by the factory should have a Dispose
method which silently does nothing. If the factory needs to provide access to a shared singleton resources (e.g. an immutable bitmap stored in a GDI object), it should return a wrapper which will notify the factory when it its Dispose
method is called; the factory can then maintain a reference count of wrapper objects and clean up the resource once it knows that no more wrappers will be created and all existing wrappers have been disposed.