【问题标题】:No implementation details visible in UserManager<TUser> class in ASP.net Core在 ASP.net Core 的 UserManager<TUser> 类中没有可见的实现细节
【发布时间】:2019-11-01 23:59:57
【问题描述】:

我对 ASP.NET 核心很陌生,我正在探索 ASP.NET 核心标识库,以了解代码在屏幕后面的工作方式。

我已经知道UserManager类负责通过调用方法来创建用户:CreateAsync(TUser user);。

但是,当我通过选择类并按 F12(转到定义)检查 Visual Studio 中的 UserManager 类时,我在 CreateAsync 方法中看不到任何实现代码。

看起来像这样:

        //
    // 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);

这是文件的开头:

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

当我去 GitHub 时,我可以看到 UserManager.cs 中的 CreateAsync 确实有这样的实现代码:

/// <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);
        }

显然我正在查看不同的两个不同文件。

谁能告诉我在哪里可以找到 Visual Studio 中 CreateAsync 方法的实现?

【问题讨论】:

标签: c# asp.net-core-mvc


【解决方案1】:

Visual Studio 不提供查看解决方案中引用的外部程序集 (.dll) 内容的可能性。

你需要一个像 dotPeek 这样的反编译器来实现你想要的:https://www.jetbrains.com/decompiler/

另一个有用的工具是 Resharper,同样来自 JetBrains。 dotPeek 是免费的,Resharper 有试用版。

【讨论】:

  • 您好,感谢您的回答。我下载并安装了 dotPeek。我仍然在此文件中看到与 Visual Studio 中相同的内容。我在 GitHub 上找不到包含内容的文件。
猜你喜欢
  • 2020-02-27
  • 1970-01-01
  • 2023-03-28
  • 2021-12-04
  • 2017-08-09
  • 1970-01-01
  • 2019-02-11
  • 1970-01-01
  • 2020-03-04
相关资源
最近更新 更多