-
Hi, I have a service that should work in the background and exposes an API to communicate with a piece of hardware via serial ports to control its functionality and logs the data generated by it to a file. The service is added as a Singleton and all this is working fine up to the point where it must orderly disconnect from the hardware. The service starts at the first invoication of one of its APIs and ends when the App exits. The problem I'm facing now is that the service's Dispose is never called at App exit time. public sealed class LogController : IDisposable and injected like this (without interface in the example, although the inteface declaring IDisposable should work as well in theory) services.AddSingleton{LogController}(); // { } should be angle brackets but I don't know how to escape them here.... but what I find is that a break point on Dispose() is not hit wen the App exits. The documentation enphasizes that "Services resolved from the container should never be disposed by the developer." Am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found the answer, it was in the warnings that I didn't pay attention for a quick test. It turns out that ILogController added void Dispose() to the interface behind my back hiding the class implementation. (I added IDisposable initially to the interface). |
Beta Was this translation helpful? Give feedback.
I found the answer, it was in the warnings that I didn't pay attention for a quick test. It turns out that ILogController added void Dispose() to the interface behind my back hiding the class implementation. (I added IDisposable initially to the interface).