Open Closed

Abp Custom Setting Provider #6723


User avatar
0
imranStem created

I have microservice architecture. I have create new setting provider in administration microservice.

Custom Setting Definition Provider

public class CustomSettingDefinitionProvider : SettingDefinitionProvider, ITransientDependency
    {
        public override void Define(ISettingDefinitionContext context)
        {
            context.Add(new SettingDefinition("TotalRank", ""));
        }

    }

Custom Setting Management Provider

 public class CustomSettingManagementProvider : SettingManagementProvider, ITransientDependency
    {
        public override string Name => "W";
        public CustomSettingManagementProvider(ISettingManagementStore store)
        : base(store)
        {
        }
    }

Custom Setting Value Provider

public class CustomSettingValueProvider : SettingValueProvider
    {
        public override string Name => "W";

        public CustomSettingValueProvider(ISettingStore settingStore)
            : base(settingStore)
        {
        }

        public override Task<string> GetOrNullAsync(SettingDefinition setting)
        {
            return SettingStore.GetOrNullAsync(setting.Name, Name, null);
        }

        public override Task<List<SettingValue>> GetAllAsync(SettingDefinition[] settings)
        {
            return SettingStore.GetAllAsync(settings.Select(x => x.Name).ToArray(), Name, null);
        }
    }

I have registered custom setting definition and provider in AdministrationServiceApplicationModule

 Configure<AbpSettingOptions>(options =>
        {
            options.DefinitionProviders.Add<CustomSettingDefinitionProvider>();
        });
        Configure<SettingManagementOptions>(options =>
        {
            options.Providers.Add<CustomSettingManagementProvider>();
        });

I can add the settings by above configuration in database.

Now, I want to read the custom setting in another microservice so I have created custom setting value provider in my another microservice and I registered value provider in app module.

public class CustomSettingValueProvider : SettingValueProvider
    {
        public override string Name => "W";

        public CustomSettingValueProvider(ISettingStore settingStore)
            : base(settingStore)
        {
        }

        public override Task<string> GetOrNullAsync(SettingDefinition setting)
        {
            return SettingStore.GetOrNullAsync(setting.Name, Name, null);
        }

        public override Task<List<SettingValue>> GetAllAsync(SettingDefinition[] settings)
        {
            return SettingStore.GetAllAsync(settings.Select(v => v.Name).ToArray(), Name, null);
        }
    }
 Configure<AbpSettingOptions>(options =>
        {
            options.ValueProviders.Add<CustomSettingValueProvider>();
        });

When I read the custom setting, it giving the null value.

var setting = await _customSettingValueProvider.GetOrNullAsync(new SettingDefinition("TotalRank")) ;

I also check with provider key but it always return null value.

I have already read the setting provider document and its not giving any details for microservice architecture to read the custom setting provider from another application.

  • ABP Framework version: v7.4.2
  • UI Type: Angular
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

8 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Member

    Hello ,

    Try to add Classname in Add() method just like show in doucmentation.

    Thank you.

  • User Avatar
    0
    imranStem created

    I have already added classname in add method in administrator microservice.

  • User Avatar
    0
    imranStem created

    Any update on this?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Now, I want to read the custom setting in another microservice so I have created custom setting value provider in my another microservice and I registered value provider in app module.

    You only need to add this to the administration microservice once.

    I have registered custom setting definition and provider in AdministrationServiceApplicationModule

    You can try to move this to Domain module layer.

  • User Avatar
    0
    imranStem created

    I can get the settings value by ISettingStore but how can I update the setting value from another microservice because ISettingManager is not available.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    because ISettingManager is not available.

    You can depend on the AbpSettingManagementDomainModule and use ISettingManager, Your MicroService.HttpApi.Host already depends on SettingManagement module.

  • User Avatar
    0
    imranStem created

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You're welcome

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on June 20, 2025, 11:20