一氮趋、概述
無
二煌妈、使用
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<AppFeatureProvider>();
2.3 調(diào)用
2.3.1通過特性
//ExportToExcel(是否為當(dāng)前用戶啟用)
//如果啟用那么這個(gè)方法會(huì)被執(zhí)行,如果沒有被啟用則拋出異常喻圃。
[RequiresFeature("ExportToExcel")]
public async Task<FileDto> GetReportToExcel(...)
{
}
2.3.2 使用IFeatureChecker
public async Task<FileDto> 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');