title: How to create a class extension in asp.net core?
body: <p>I want to create my custom service via using <code>userManager</code>. But I don't know how to access to <code>dbContext</code>.</p>
  
  <pre><code>public static class UserManagerExtensions
  {
      public static async Task&lt;IdentityResult&gt; AddProfileAsync(this UserManager&lt;ApplicationUser&gt; userManager, UserProfileModel model)
      {
  
          // how to access to dbContext here???
  
          if (await dbContext.SaveChangesAsync() &gt; 0)
          {
              return IdentityResult.Success;
          }
  
          return IdentityResult.Failed();
      }
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>public class UserController : Controller
  {
      private readonly UserManager&lt;ApplicationUser&gt; _userManager;
  
      public UserController(UserManager&lt;ApplicationUser&gt; userManager)
      {
          _userManager = userManager;
      }
  
      public async Task&lt;IActionResult&gt; Update(UserProfileModel model)
      {
          await _userManager.AddProfileAsync(model);
  
          return View();
      }
  }
  </code></pre>
  
  <p>How to access <code>DbContext</code> class inside a static class?</p>
  
  <p>Thank you!</p>