Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Is there a need for separate SignInManager<TUser> and UserManager<TUser>?

Is there a need for separate SignInManager<TUser> and UserManager<TUser>?

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
3 Posts 3 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hpjchobbes
    wrote on last edited by
    #1

    I have been looking at the code that gets generated when you add new scaffold items for Identity into an web application. I notice that often a UserManager<TUser> gets injected along with a SignInManager<TUser>. It seems that the SignInManager has a property for UserManager. Is there a reason to have them injected separately instead of just injecting and using the SignInManager? Can there be situations where the UserManager property is null in the SignInManager but would have been injected into the constructor?

    // Should we always have a separate _userManager injected?
    var userId = await _userManager.GetUserIdAsync(user);

    // Or would this also work, but some may not like the multiple chaining?
    var userId = await _signInManager.UserManager.GetUserIdAsync(user);

    D S 2 Replies Last reply
    0
    • H hpjchobbes

      I have been looking at the code that gets generated when you add new scaffold items for Identity into an web application. I notice that often a UserManager<TUser> gets injected along with a SignInManager<TUser>. It seems that the SignInManager has a property for UserManager. Is there a reason to have them injected separately instead of just injecting and using the SignInManager? Can there be situations where the UserManager property is null in the SignInManager but would have been injected into the constructor?

      // Should we always have a separate _userManager injected?
      var userId = await _userManager.GetUserIdAsync(user);

      // Or would this also work, but some may not like the multiple chaining?
      var userId = await _signInManager.UserManager.GetUserIdAsync(user);

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      It comes down to separation of concerns. SignInManager is used by the UI to get credentials, authenticate, and maintain login state, while UserManager is concerned with managing the database of users and authenticating credentials passed to it by a SignInManager. Yes, the SignInManager has a UserManager property, but you have to pass a configured UserManager to the SignInManager when creating an instance of that.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • H hpjchobbes

        I have been looking at the code that gets generated when you add new scaffold items for Identity into an web application. I notice that often a UserManager<TUser> gets injected along with a SignInManager<TUser>. It seems that the SignInManager has a property for UserManager. Is there a reason to have them injected separately instead of just injecting and using the SignInManager? Can there be situations where the UserManager property is null in the SignInManager but would have been injected into the constructor?

        // Should we always have a separate _userManager injected?
        var userId = await _userManager.GetUserIdAsync(user);

        // Or would this also work, but some may not like the multiple chaining?
        var userId = await _signInManager.UserManager.GetUserIdAsync(user);

        S Offline
        S Offline
        Sardar Mudassar Ali Khan SSE
        wrote on last edited by
        #3

        Yes, ASP.NET Identity requires distinct SignInManager and UserManager classes.

        The management of user accounts, including their creation, updating, and deletion, password resets, and email address confirmations, is under the purview of the UserManager class

        SignInManager class is responsible for handling the authentication and sign-in process for the application

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups