c# - 获取configurationRefresher为null

标签 c# azure azure-app-configuration

我正在使用带有 azure 功能的 azure 应用程序配置。所以我想自动刷新键,但我的configurationRefresher始终为null。

 builder.AddAzureAppConfiguration(appConfigurationOptions =>
            {
                appConfigurationOptions
                    .Select(ConfigurationKeys.AZURE_FUNC_TEST)
                    .Select(KeyFilter.Any, environment.EnvironmentName)
                    .ConfigureRefresh(refreshOptions =>
                    {
                        refreshOptions.Register(ConfigurationKeys.AZURE_FUNC_TEST, true);
                        refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(1));
                    })
                    .UseFeatureFlags(flagOptions =>
                    {
                        flagOptions.Label = environment.EnvironmentName;
                        flagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(30);
                    })
                    .GetRefresher();
                configurationRefresher = appConfigurationOptions.GetRefresher();
            },true);
            return builder;

我找到了它为空的原因,实际上我在辅助类中有上面的代码,然后我将上面的结果传递给启动类,然后在它构建的启动类中。因此我没有获得值(value)。但是有什么方法可以获取启动类和上面代码中的值,我希望它在辅助类中

最佳答案

AddAzureAppConfiguration 方法采用委托(delegate)作为输入。仅当在 ConfigurationBuilder 实例上调用 Build 方法时,此委托(delegate)才会运行。

为了在帮助程序类中初始化 configurationRefresher 实例,您可以调用 ConfigurationBuilder.Build 方法来获取 IConfiguration 实例>。然后可以在依赖项注入(inject)容器中注册该实例。

IConfiguration configuration = builder.AddAzureAppConfiguration(appConfigurationOptions =>
{
    appConfigurationOptions
        .Select(ConfigurationKeys.AZURE_FUNC_TEST)
        .Select(KeyFilter.Any, environment.EnvironmentName)
        .ConfigureRefresh(refreshOptions =>
        {
            refreshOptions.Register(ConfigurationKeys.AZURE_FUNC_TEST, true);
            refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(1));
        })
        .UseFeatureFlags(flagOptions =>
        {
            flagOptions.Label = environment.EnvironmentName;
            flagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(30);
        })
        .GetRefresher();

    configurationRefresher = appConfigurationOptions.GetRefresher();
}, true);

return configuration;

关于c# - 获取configurationRefresher为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64662264/

相关文章:

c# - 将具有可变属性的 JSON 对象解析为强类型对象

c# - 无法通过一个查询使用 Include 或 ThenInclude 或 Select/Many 加载相关数据

c# - 如何在 app.xaml 中将 datagrid SelectedIndex 设置为 -1

azure - 是否有一些针对 WaIISHost 崩溃的 Azure 云服务日志文件

azure - 我可以将 ASP.NET Core 登录路由到不同的 Azure B2C 策略吗?

Azure 应用程序配置推送任务 - 如何使用此任务在 azure 应用程序配置中部署 key 保管库引用值?

c# - 是否可以在 ASP.NET Core 中组合 [FromRoute] 和 [FromBody]?

azure - 如何根据应用程序角色确定 AAD 企业应用程序配置范围

azure - 如何在Azure应用程序配置中添加 map

从 GitHub 部署 Azure Web 服务失败