ABP 功能管理 - 如何添加新范围?
ABP Feature Management - How to add a new scope?
我正在使用 ASP.NET 样板和零模块开发一个事件管理应用程序。
ASP.NET 样板中包含的功能管理允许将功能范围限定到版本或租户。
我想知道是否可以将功能扩展到事件范围内,这样我就可以将我们应用程序的特定功能单独分配给租户创建的每个事件。
这可能吗?使用 ABP 实现此功能的最佳方法是什么?
I would like to know if it's possible to extend features to be scoped to events... Is this possible?
当然可以。您可以:
- 子类
Feature
- 子类
FeatureSetting
- 创建一个新的
FeatureScopes
枚举以包含 Events
- 实施并替换
IFeatureChecker
- 实施并替换
IFeatureManager
- 覆盖
FeatureValueStore
中的方法
看起来工作量很大。但这样做是为了可维护性和关注点分离。
What is the best way to implement this with ABP?
您最好按原样使用 Feature
,为租户启用,然后替换 FeatureChecker
:
public async Task<string> GetValueAsync(int tenantId, string name)
{
var feature = _featureManager.Get(name);
var value = await FeatureValueStore.GetValueOrNullAsync(tenantId, feature);
if (value == null)
{
return feature.DefaultValue;
}
// Check if Feature is enabled for Event
// ...
return value;
}
我正在使用 ASP.NET 样板和零模块开发一个事件管理应用程序。
ASP.NET 样板中包含的功能管理允许将功能范围限定到版本或租户。
我想知道是否可以将功能扩展到事件范围内,这样我就可以将我们应用程序的特定功能单独分配给租户创建的每个事件。
这可能吗?使用 ABP 实现此功能的最佳方法是什么?
I would like to know if it's possible to extend features to be scoped to events... Is this possible?
当然可以。您可以:
- 子类
Feature
- 子类
FeatureSetting
- 创建一个新的
FeatureScopes
枚举以包含Events
- 实施并替换
IFeatureChecker
- 实施并替换
IFeatureManager
- 覆盖
FeatureValueStore
中的方法
看起来工作量很大。但这样做是为了可维护性和关注点分离。
What is the best way to implement this with ABP?
您最好按原样使用 Feature
,为租户启用,然后替换 FeatureChecker
:
public async Task<string> GetValueAsync(int tenantId, string name)
{
var feature = _featureManager.Get(name);
var value = await FeatureValueStore.GetValueOrNullAsync(tenantId, feature);
if (value == null)
{
return feature.DefaultValue;
}
// Check if Feature is enabled for Event
// ...
return value;
}