14.功能FeatureProvider

一、概述

二、使用

2.1定义

public class AppFeatureProvider : FeatureProvider
{
    public override void SetFeatures(IFeatureDefinitionContext context)
    {
        var sampleBooleanFeature = context.Create("SampleBooleanFeature", defaultValue: "false");
        sampleBooleanFeature.CreateChildFeature("SampleNumericFeature", defaultValue: "10");
        context.Create("SampleSelectionFeature", defaultValue: "B");
    }
}

2.2 配置

Configuration.Features.Providers.Add();

2.3 调用

2.3.1通过特性

//ExportToExcel(是否为当前用户启用) 
//如果启用那么这个方法会被执行,如果没有被启用则抛出异常。
[RequiresFeature("ExportToExcel")]
public async Task GetReportToExcel(...)
{
}

2.3.2 使用IFeatureChecker

public async Task GetReportToExcel(...)
{
    if (await FeatureChecker.IsEnabledAsync("ExportToExcel"))
    {
          throw new AbpAuthorizationException("You don't have ExportToExcel");
    }   
}
//获取值
FeatureChecker.GetValue("MaxTaskCreationLimitPerMonth"))

2.3.3 通过客户端

//isEnabled
var isEnabled = abp.features.isEnabled('SampleBooleanFeature');
//getValue
var value = abp.features.getValue('SampleNumericFeature');

你可能感兴趣的:(14.功能FeatureProvider)