我正在尝试从 Azure 应用程序配置读取 eventthubname 和连接字符串,而不是函数应用程序设置,但我无法让它工作,如果我从函数应用程序本身它工作正常,但我需要从应用程序配置集中配置存储读取.
到目前为止,这是我的小功能
public class CDSSoftDelete
{
static string _eventHubname = null;
string _connectionString;
private readonly IConfiguration _config;
public CDSSoftDelete(IConfiguration config, IConfigurationRefresher configurationRefresher)
{
if (config == null) throw new ArgumentNullException(nameof(config));
if (configurationRefresher == null) throw new ArgumentNullException(nameof(configurationRefresher));
configurationRefresher.TryRefreshAsync();
_config = config;
_eventHubname = config["SLQueueManager:Settings:EventHubName"];
_connectionString = config["SLQueueManager:Settings:EventHubConnectionString"];
}
[FunctionName("CDSSoftDelete")]
public async Task Run([EventHubTrigger(_config["SLQueueManager:Settings:EventHubName"], Connection = _connectionString)] EventData[] events, ILogger log)
{
}
}
但这不起作用,因为 _config 变量没有对象引用,所以它有点问题 22
如何正确读取这些配置设置?