Table of Contents
Intro
ABP Feature system is used to enable, disable or change the behavior of the application features on runtime.
Create feature constant
public static class TodoFeatures
{
public const string Todo = "Todo";
public const string MaxTodoPerUser = "MaxTodoPerUser";
}
Create feature definition provider
public class TodoFeatureDefinitionProvider : FeatureDefinitionProvider
{
public override void Define(IFeatureDefinitionContext context)
{
var myGroup = context.AddGroup("MyTodoApp");
myGroup.AddFeature(
TodoFeatures.Todo,
defaultValue: "false",
displayName: L("Todo"),
valueType: new ToggleStringValueType()
);
myGroup.AddFeature(
TodoFeatures.MaxTodoPerUser,
defaultValue: "10",
displayName: L("MaxTodoPerUser"),
valueType: new FreeTextStringValueType(
new NumericValueValidator(0, 1000000))
);
}
private static LocalizableString L(string name)
{
return LocalizableString.Create<TodosResource>(name);
}
}
Expose api base on feature
You can use the RequiresFeature
attribute to restrict access to the api endpoint.
[RequiresFeature(TodoFeatures.Todo)]
IFeatureChecker service
you can use the FeatureChecker service to check if the feature is enabled or not and get the value of the feature.
var maxTodoPerUser = await FeatureChecker.GetAsync<int>(TodoFeatures.MaxTodoPerUser);
For more info check the official docs : https://docs.abp.io/en/abp/latest/Features
Related Posts
Changing theme for your ABP app. Part 10
In this post we will explore how to change the theme for your ABP application.
10/26/2021
Deploy ABP Framework dotnet core tiered app to docker swarm. Part 9
In this post we will see how to deploy your dotnet core app with docker container.
9/28/2021
Centralized logging for .net core ABP microservices app using Seq. Part 8
In this post we will see how to implement a central logging system for your ABP app using Seq.
9/26/2021