abp
feature
ABP Feature system is used to enable, disable or change the behavior of the application features on runtime.
1public static class TodoFeatures 2{ 3 public const string Todo = "Todo"; 4 public const string MaxTodoPerUser = "MaxTodoPerUser"; 5}
1public class TodoFeatureDefinitionProvider : FeatureDefinitionProvider 2{ 3 public override void Define(IFeatureDefinitionContext context) 4 { 5 var myGroup = context.AddGroup("MyTodoApp"); 6 7 myGroup.AddFeature( 8 TodoFeatures.Todo, 9 defaultValue: "false", 10 displayName: L("Todo"), 11 valueType: new ToggleStringValueType() 12 ); 13 14 myGroup.AddFeature( 15 TodoFeatures.MaxTodoPerUser, 16 defaultValue: "10", 17 displayName: L("MaxTodoPerUser"), 18 valueType: new FreeTextStringValueType( 19 new NumericValueValidator(0, 1000000)) 20 ); 21 } 22 23 private static LocalizableString L(string name) 24 { 25 return LocalizableString.Create<TodosResource>(name); 26 } 27}
You can use the RequiresFeature
attribute to restrict access to the api endpoint.
1[RequiresFeature(TodoFeatures.Todo)]
you can use the FeatureChecker service to check if the feature is enabled or not and get the value of the feature.
1var maxTodoPerUser = await FeatureChecker.GetAsync<int>(TodoFeatures.MaxTodoPerUser);
For more info check the official docs : https://docs.abp.io/en/abp/latest/Features