Is there any particular reason to have <xxx>IntegrationEventService implement IDisposable?
See original GitHub issueCan’t help wondering the purpose of using private volatile bool disposedValue;
in every implementation of integration event service, as well as the
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
(_eventLogService as IDisposable)?.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
code snippet. What are they, and is it really necessary to do so?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
c# - Is there any benefit to implementing IDisposable on ...
There are only 2 reasons for implementing IDisposable on a type. The type contains native resources which must be freed when the type...
Read more >Using objects that implement IDisposable
Learn how to use objects that implement the IDisposable interface in .NET. Types that use unmanaged resources implement IDisposable to allow ...
Read more >What is the use of IDisposable interface? : r/csharp
The reason to implement IDisposable is if a type holds some expensive resource that needs to be cleaned up immediately. The 99% use...
Read more >Implement a Dispose method
The Dispose method is primarily implemented to release unmanaged resources. When working with instance members that are IDisposable ...
Read more >IDisposable, Done Right
The reason for IDisposable is deterministic release of references by an object (something that used to happen manually with unmanaged languages ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, the integration services are not wrapped in any usings, instead they are used just like any regular injected scoped service in the controller. So I don’t really see the reasoning of implementing IDisposable here.
Furthermore, I’m more confused about the use of volatile boolean variable. Not a clue of why it is done this way.
@sughosneo So why was the dispose mechanism implemented like this? What’s the problem of using the normal way of Dispose method, or even not implementing IDisposable at all? The only thing that will get disposed of, as far as I can tell, is the DbContext for integration event log. Don’t know why this context requires explicit disposal, unlike the regular business DbContext that got injected in many places.