abp icon indicating copy to clipboard operation
abp copied to clipboard

How to override IdentityUserManager?

Open gdlcf88 opened this issue 7 years ago • 3 comments

https://github.com/abpframework/abp/blob/0.19.0/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs

I need to override IdentityUserManager, but these code doesn't work:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Services;
using Volo.Abp.Identity;
using Volo.Abp.Threading;
using VoloIdentityUserManager = Volo.Abp.Identity.IdentityUserManager; 

namespace MyProject.Abp.Identity
{
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(VoloIdentityUserManager))]
    public class IdentityUserManager : VoloIdentityUserManager
    {
        protected override CancellationToken CancellationToken => _cancellationTokenProvider.Token;

        private readonly ICancellationTokenProvider _cancellationTokenProvider;
        
        public IdentityUserManager(IdentityUserStore store, IOptions<IdentityOptions> optionsAccessor,
            IPasswordHasher<IdentityUser> passwordHasher, IEnumerable<IUserValidator<IdentityUser>> userValidators,
            IEnumerable<IPasswordValidator<IdentityUser>> passwordValidators, ILookupNormalizer keyNormalizer,
            IdentityErrorDescriber errors, IServiceProvider services, ILogger<VoloIdentityUserManager> logger,
            ICancellationTokenProvider cancellationTokenProvider) : base(store, optionsAccessor, passwordHasher,
            userValidators, passwordValidators, keyNormalizer, errors, services, logger, cancellationTokenProvider)
        {
            _cancellationTokenProvider = cancellationTokenProvider;
        }

        public new async Task<IdentityResult> SetRolesAsync([NotNull] IdentityUser user, [NotNull] IEnumerable<string> roleNames)
        {
            throw new ApplicationException("Replace successful.");
        }
    }
}

gdlcf88 avatar Oct 09 '19 12:10 gdlcf88

Closed by https://github.com/abpframework/abp/commit/52513c9b986bd4e76129076ce845a80bf7b101a5

maliming avatar Oct 10 '19 04:10 maliming

Does this issue fixed? I have the same question. s1 s2

abllyboy avatar Dec 20 '19 03:12 abllyboy

@abllyboy Replacing the controller may also have to deal with routing issues. Can you create a new issue?

maliming avatar Dec 20 '19 03:12 maliming