Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there any particular reason to have <xxx>IntegrationEventService implement IDisposable?

See original GitHub issue

Can’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);

code snippet. What are they, and is it really necessary to do so?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

nicholasyincommented, Sep 30, 2021

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.

nicholasyincommented, Sep 27, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found