【发布时间】: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