- Published on
Application features with dotnet core and ABP. Part 4
📖1 min read
Series: ABP Framework - Getting started
This post is part of the ABP Framework - Getting started series.
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
cs
public static class TodoFeatures
{
public const string Todo = "Todo";
public const string MaxTodoPerUser = "MaxTodoPerUser";
}
Create feature definition provider
cs
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.
cs
[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.
cs
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
Continue reading with these related articles
4 min read
ABP Framework - Getting startedPart 10
Changing theme for your ABP app. Part 10
In this post we will explore how to change the theme for your ABP application.
abpbootstraptheme
Read article
4 min read
ABP Framework - Getting startedPart 9
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.
abpdockerdeployment
Read article
1 min read
ABP Framework - Getting startedPart 8
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.
abpseqdotnet
Read article