title: Get logged in user details from identity in service
body: <p>I can get details of logged in user from controller injecting IHttpContextAccessor httpContextAccessor. But when I try it in my service, it does not work. I get these error</p>
  
  <pre><code>{System.Exception: 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 a...
  </code></pre>
  
  <p>What I have done is create an <strong>IUserService</strong> interface. Then added GetUser method there with its implementation as:</p>
  
  <pre><code>public class UserService : IUserService
  {
      private readonly IHttpContextAccessor _context;
      private readonly UserManager&lt;User&gt; _userManager;
      public UserService(IHttpContextAccessor context, UserManager&lt;User&gt; userManager)
      {
          _context = context;
          _userManager = userManager;
      }
      public async Task&lt;User&gt; GetUser()
      {
          return await _userManager.FindByNameAsync(_context.HttpContext.User.Identity.Name);
      }
  }
  </code></pre>
  
  <p>I have added  <code>services.AddSingleton&lt;IUserService, UserService&gt;();</code> in my IServiceCollection too. </p>