简体   繁体   中英

No implementation details visible in UserManager<TUser> class in ASP.net Core

I am quite new to ASP.NET core and i am exploring the ASP.NET core Identity library to see how the code works behind the screen.

I already know that the UserManager class is responsible for creating an user by calling the method: CreateAsync(TUser user);.

However when i inspect the UserManager class in Visual Studio by selecting the class and pressing F12 (Go To Definition) i do not see any implementation code in the CreateAsync method.

It looks like this:

        //
    // Summary:
    //     Creates the specified user in the backing store with no password, as an asynchronous
    //     operation.
    //
    // Parameters:
    //   user:
    //     The user to create.
    //
    // Returns:
    //     The System.Threading.Tasks.Task that represents the asynchronous operation, containing
    //     the Microsoft.AspNetCore.Identity.IdentityResult of the operation.
    [DebuggerStepThrough]
    public virtual Task<IdentityResult> CreateAsync(TUser user);

This is the beginning of the file:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Microsoft.AspNetCore.Identity
{
    //
    // Summary:
    //     Provides the APIs for managing user in a persistence store.
    //
    // Type parameters:
    //   TUser:
    //     The type encapsulating a user.
    public class UserManager<TUser> : IDisposable where TUser : class

When i go to GitHub i can see that the CreateAsync in the UserManager.cs indeed has implementation code like this:

/// <summary>
        /// Creates the specified <paramref name="user"/> in the backing store with given password,
        /// as an asynchronous operation.
        /// </summary>
        /// <param name="user">The user to create.</param>
        /// <param name="password">The password for the user to hash and store.</param>
        /// <returns>
        /// The <see cref="Task"/> that represents the asynchronous operation, containing the <see cref="IdentityResult"/>
        /// of the operation.
        /// </returns>
        public virtual async Task<IdentityResult> CreateAsync(TUser user, string password)
        {
            ThrowIfDisposed();
            var passwordStore = GetPasswordStore();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }
            var result = await UpdatePasswordHash(passwordStore, user, password);
            if (!result.Succeeded)
            {
                return result;
            }
            return await CreateAsync(user);
        }

Obviously i am looking at different two different files.

Can anyone tell me where i can find the implementation of the CreateAsync method in Visual Studio?

Visual Studio doesn't offer the possibility of seing the content of an external assembly(.dll) that's being referenced in your solution.

You will need a decompiler like dotPeek to achieve what you want: https://www.jetbrains.com/decompiler/

Another useful tool in your case is Resharper, as well from JetBrains. dotPeek is free and Resharper has a trial version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM