title: How to use a dbcontext in a static class? (ObjectDisposedException)
body: <p>Hey I just recently learnt how to use extension methods and pretty excited to implement it in my current project.</p>
  <p><strong>My objective:</strong>
  I want to check whether an entry exists in my table in a helper class, since I'm going to use it in multiple controllers to be able to determine which navigation links to show in my navbar:<a href="https://i.stack.imgur.com/QMqsv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QMqsv.png" alt="enter image description here" /></a></p>
  <p><strong>My Issue:</strong>
  I don't know how to access my dbcontext in my static helper class. My dbcontext controller takes an argument I don't know how to pass in my static class. I think creating a new dbcontext would solve my scope issue explained below but I don't see how I can pass the optional argument to my constructor.</p>
  <p><a href="https://i.stack.imgur.com/5rlc6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5rlc6.png" alt="enter image description here" /></a></p>
  <p>It is currently configured in the Startup.cs class.
  <a href="https://i.stack.imgur.com/FrYUl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FrYUl.png" alt="enter image description here" /></a></p>
  <p><strong>What I tried:</strong>
  Passing the ApplicationDbContext as an argument. This works for a single method call in my controller, but when calling multiple extension methods (To check which game accounts the user has) I get a ObjectDisposedException.</p>
  <blockquote>
  <p>ObjectDisposedException: Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
  Object name: 'ApplicationDbContext'.</p>
  </blockquote>
  <p>From what I understand it is a scope issue where the first method call disposes the context when it's done and I'm trying to use the same context in the next call? What can I do to work around that?</p>
  <p>I tried reading this link <a href="https://stackoverflow.com/questions/38704025/cannot-access-a-disposed-object-in-asp-net-core-when-injecting-dbcontext">Cannot access a disposed of object in ASP.NET Core when injecting DbContext</a> but it didn't help me since it requires the ApplicationBuilder which is in the Startup.cs class.</p>
  <p><a href="https://i.stack.imgur.com/FDhc9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FDhc9.png" alt="enter image description here" /></a></p>
  <p><strong>Solution Update</strong>
  I disposed the dbcontext after every method call because I put it into a variable. Instead, I call it directly on the passed context and it works:</p>
  <p><a href="https://i.stack.imgur.com/ryxl2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ryxl2.png" alt="enter image description here" /></a></p>