This repository has been archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 871
/
AspNetRoleManager.cs
45 lines (41 loc) · 2.12 KB
/
AspNetRoleManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Identity
{
/// <summary>
/// Provides the APIs for managing roles in a persistence store.
/// </summary>
/// <typeparam name="TRole">The type encapsulating a role.</typeparam>
public class AspNetRoleManager<TRole> : RoleManager<TRole>, IDisposable where TRole : class
{
private readonly CancellationToken _cancel;
/// <summary>
/// Constructs a new instance of <see cref="RoleManager{TRole}"/>.
/// </summary>
/// <param name="store">The persistence store the manager will operate over.</param>
/// <param name="roleValidators">A collection of validators for roles.</param>
/// <param name="keyNormalizer">The normalizer to use when normalizing role names to keys.</param>
/// <param name="errors">The <see cref="IdentityErrorDescriber"/> used to provider error messages.</param>
/// <param name="logger">The logger used to log messages, warnings and errors.</param>
/// <param name="contextAccessor">The accessor used to access the <see cref="HttpContext"/>.</param>
public AspNetRoleManager(IRoleStore<TRole> store,
IEnumerable<IRoleValidator<TRole>> roleValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
ILogger<RoleManager<TRole>> logger,
IHttpContextAccessor contextAccessor)
: base(store, roleValidators, keyNormalizer, errors, logger)
{
_cancel = contextAccessor?.HttpContext?.RequestAborted ?? CancellationToken.None;
}
/// <summary>
/// The cancellation token associated with the current HttpContext.RequestAborted or CancellationToken.None if unavailable.
/// </summary>
protected override CancellationToken CancellationToken => _cancel;
}
}