Open Closed

Custom FeatureValueProvider Not Invoked When DefaultValue Is Set in .AddFeature #9243


User avatar
0
karl.ettinger@energieag.at created

Hi!

I have implemented a FeatureValueProvider for roles (RoleBasedFeatureValueProvider) and registered it as the first provider in the list of FeatureValueProviders. However, I noticed that when I specify a defaultValue in .AddFeature, my RoleBasedFeatureValueProvider is not invoked. If I leave out the defaultValue in .AddFeature, the text fields of type FreeTextStringValueType appear disabled in the Blazor UI under Administrator → Saas → Editions → Default Edition → Features. This behavior seems quite unexpected. As a workaround, I had to modify my RoleBasedFeatureValueProvider so that, upon the first call to FeatureChecker.IsEnabledAsync, an entry is created in the AbpFeatureValues table.

Could you please explain why my RoleBasedFeatureValueProvider, although registered first in the list, is ignored when a defaultValue is provided in .AddFeature?

Thank you!


10 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share full code or a test project to reproduce?

    liming.ma@volosoft.com

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to override the Blazor FeatureManagementModal?

    Typically, a feature will have a default value

    using Volo.Abp.DependencyInjection;
    using Volo.Abp.FeatureManagement.Blazor.Components;
    using Volo.Abp.Features;
    
    namespace EagEz.Fvp.Blazor;
    
    [ExposeServices(typeof(FeatureManagementModal))]
    [Dependency(ReplaceServices = true)]
    public class MyFeatureManagementModal : FeatureManagementModal
    {
        protected override bool IsDisabled(string providerName)
        {
            return providerName != null && providerName != ProviderName && providerName != DefaultValueFeatureValueProvider.ProviderName;
        }
    }
    
    
  • User Avatar
    0
    karl.ettinger@energieag.at created

    Hi!

    ... Typically, a feature will have a default value

    Yes, that's what I intended to do as well. But then my FvpRoleBasedFeatureValueProvider is not invoked, even though it’s registered first in the list. Instead, a default FeatureValueProvider is used, which doesn’t know how to handle my default values and throws an exception. See the test project under screenshot\02 Test-2 Exception.png. And that's the problem.

    • Without a default value, FvpRoleBasedFeatureValueProvider is used.
    • With a default value, FvpRoleBasedFeatureValueProvider is not used.

    What do I need to do to ensure that my FvpRoleBasedFeatureValueProvider is always used when it is registered first?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will test it again.

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The RequireFeatures method of ApplicationMenuItem requires the feature that is ToggleStringValueType

    Your features both are FreeTextStringValueType

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Configure<AbpFeatureOptions>(options =>
    {
        options.ValueProviders.Insert(0, typeof(FvpRoleBasedFeatureValueProvider));
    });
    

    The valueProviders order is

    DefaultValueFeatureValueProvider
    EditionFeatureValueProvider
    TenantFeatureValueProvider
    

    Your FvpRoleBasedFeatureValueProvider should be added after DefaultValueFeatureValueProvider,

    eg:

    DefaultValueFeatureValueProvider
    
    FvpRoleBasedFeatureValueProvider
    
    EditionFeatureValueProvider
    TenantFeatureValueProvider
    

    But this depends on your business logic. You can add before TenantFeatureValueProvider.

    eg:

    DefaultValueFeatureValueProvider
    EditionFeatureValueProvider
    TenantFeatureValueProviderr
    
    FvpRoleBasedFeatureValueProvider
    
  • User Avatar
    0
    karl.ettinger@energieag.at created

    hi,

    With my configuration:

    Configure<AbpFeatureOptions>(options =>
    {
        options.ValueProviders.Insert(0, typeof(FvpRoleBasedFeatureValueProvider));
    });
    

    In which order is the ValueProvider inserted? I assume that the ValueProvider is inserted at the beginning of the list and is therefore the first one to be called.

    Is that correct?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    is therefore the first one to be called.

    Add it to the last position.

    Configure<AbpFeatureOptions>(options =>
    {
        options.ValueProviders.Add<FvpRoleBasedFeatureValueProvider>();
    });
    
  • User Avatar
    0
    karl.ettinger@energieag.at created

    Thanks, that was it!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
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 September 12, 2025, 10:20