Open Closed

Replacing a dynamic claim contributor #7920


User avatar
0
aZee created
  • ABP Framework version: v8.2.3

Hello, can I replace IdentitySessionDynamicClaimsPrincipalContributor with my own implementation? If so, how can I do it?


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Of course, you can replace it.

    for example:

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IdentitySessionDynamicClaimsPrincipalContributor))]
    public class MyIdentitySessionDynamicClaimsPrincipalContributor : IdentitySessionDynamicClaimsPrincipalContributor
    {
        public override Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
        {
            ....
            return base.ContributeAsync(context);
        }
    }
    
  • User Avatar
    0
    aZee created

    Hello, thank you for your reply. However, I had to use the IServiceCollection.Replace method instead of Dependency attribute. Here's my working code : MyIdentitySessionDynamicClaimsPrincipalContributor.cs

    public class MyIdentitySessionDynamicClaimsPrincipalContributor : IdentitySessionDynamicClaimsPrincipalContributor
    {
        public override Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
        {
            ...
        }
    }
    

    MyModule.cs

    public class MyModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            ...
            context.Services.Replace(
                ServiceDescriptor.Transient<
                	IdentitySessionDynamicClaimsPrincipalContributor,
                    MyIdentitySessionDynamicClaimsPrincipalContributor 
                >());
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09