1 // Copyright (c) .NET Foundation. All rights reserved. 2 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 4 using System; 5 using System.Collections.Generic; 6 using System.Threading; 7 using Microsoft.AspNetCore.Http; 8 using Microsoft.Extensions.DependencyInjection; 9 using Microsoft.Extensions.Logging; 10 using Microsoft.Extensions.Options; 11 12 namespace Microsoft.AspNetCore.Identity 13 { 14 /// <summary> 15 /// Provides the APIs for managing user in a persistence store. 16 /// </summary> 17 /// <typeparam name="TUser">The type encapsulating a user.</typeparam> 18 public class AspNetUserManager<TUser> : UserManager<TUser>, IDisposable where TUser : class 19 { 20 private readonly CancellationToken _cancel; 21 22 /// <summary> 23 /// Constructs a new instance of <see cref="AspNetUserManager{TUser}"/>. 24 /// </summary> 25 /// <param name="store">The persistence store the manager will operate over.</param> 26 /// <param name="optionsAccessor">The accessor used to access the <see cref="IdentityOptions"/>.</param> 27 /// <param name="passwordHasher">The password hashing implementation to use when saving passwords.</param> 28 /// <param name="userValidators">A collection of <see cref="IUserValidator{TUser}"/> to validate users against.</param> 29 /// <param name="passwordValidators">A collection of <see cref="IPasswordValidator{TUser}"/> to validate passwords against.</param> 30 /// <param name="keyNormalizer">The <see cref="ILookupNormalizer"/> to use when generating index keys for users.</param> 31 /// <param name="errors">The <see cref="IdentityErrorDescriber"/> used to provider error messages.</param> 32 /// <param name="services">The <see cref="IServiceProvider"/> used to resolve services.</param> 33 /// <param name="logger">The logger used to log messages, warnings and errors.</param> AspNetUserManager(IUserStore<TUser> store, IOptions<IdentityOptions> optionsAccessor, IPasswordHasher<TUser> passwordHasher, IEnumerable<IUserValidator<TUser>> userValidators, IEnumerable<IPasswordValidator<TUser>> passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, ILogger<UserManager<TUser>> logger)34 public AspNetUserManager(IUserStore<TUser> store, 35 IOptions<IdentityOptions> optionsAccessor, 36 IPasswordHasher<TUser> passwordHasher, 37 IEnumerable<IUserValidator<TUser>> userValidators, 38 IEnumerable<IPasswordValidator<TUser>> passwordValidators, 39 ILookupNormalizer keyNormalizer, 40 IdentityErrorDescriber errors, 41 IServiceProvider services, 42 ILogger<UserManager<TUser>> logger) 43 : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger) 44 { 45 _cancel = services?.GetService<IHttpContextAccessor>()?.HttpContext?.RequestAborted ?? CancellationToken.None; 46 } 47 48 /// <summary> 49 /// The cancellation token associated with the current HttpContext.RequestAborted or CancellationToken.None if unavailable. 50 /// </summary> 51 protected override CancellationToken CancellationToken => _cancel; 52 } 53 } 54