![](/img/trans.png)
[英]Feature management, feature toggle, feature flags not working with Azure App Configuration Store
[英]Azure Feature Management on startup
我想使用 Azure 功能管理來驅動是否在啟動期間將服務添加到依賴.ConfigureServices(hostcontext, services =>
我能找到的唯一方法是調用 BuildServiceProvider 來獲取 IFeatureManagement。
var featureManager = services.BuildServiceProvider().GetRequiredService<IFeatureManager>();
if (featureManager.IsEnabledAsync(Features.MY_FEATURE).GetAwaiter().GetResult())
{
services.AddFeatureDependencies();
}
必須有更好的方法來做到這一點。 我在某處缺少服務擴展嗎? 像下面這樣的東西?
services.IfFeatureEnabled(Features.MY_FEATURE) {
services.AddFeatureDependencies();
}
或者也許通過使用可以獲取其他配置值的 IConfiguration 接口?
hostContext.Configuration.GetValue<bool>($"FeatureManager:{FeatureManagement.MY_FEATURE}");
我發現為此創建擴展方法很有用:
public static class ConfigurationExtensions
{
public static bool IsFeatureEnabled(this IConfiguration configuration, string feature)
{
var featureServices = new ServiceCollection();
featureServices.AddFeatureManagement(configuration);
using var provider = featureServices.BuildServiceProvider();
var manager = provider.GetRequiredService<IFeatureManager>();
return manager.IsEnabledAsync(feature).GetAwaiter().GetResult();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.