我必须在 Azure DevOps 管道中为 ARM 模板设置一个数组。我这样设置我的变量:
$foo = '["' + 'bar' + '"]'
Write-Host $foo
#######Assign Variables with Correct Value in pipeline
Write-Host "##vso[task.setvariable variable=fooVariableInPipeline]$foo"
Run Code Online (Sandbox Code Playgroud)
$foo 值很好,如预期的那样是 ["bar"] 。但是,当我在设置变量后检查下一个任务中的值时,它会删除引号并将值显示为 [bar]。
这很奇怪,我想知道这是我的问题还是一个错误?有什么解决方法吗?
目前,我已经直接使用 powershell 代码更新了我的文件。
我的 Azure 函数中有一个 redisprovider 类:
public RedisCacheProvider(ILogger<RedisCacheProvider> logger,
IConnectionMultiplexer connectionMultiplexer)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
multiplexer = connectionMultiplexer;
}
Run Code Online (Sandbox Code Playgroud)
我将此类添加为单例,但如何在启动类中初始化 Ilogger。我知道它是由 Azure Functions 注入到类中的。如果是这样,当我们需要在启动时初始化该类的其他对象时,如何在启动类中管理它?
services.AddSingleton<ICacheProvider>(serviceProvider =>
new RedisCacheProvider(**???**, serviceProvider.GetRequiredService<IConnectionMultiplexer>()));
Run Code Online (Sandbox Code Playgroud)
通常,我这样做:
services.AddSingleton<IHttpService, HttpService>();
Run Code Online (Sandbox Code Playgroud)
在 RedisProvider 类中,我需要传递连接字符串。那么当我传递IConnectionMultiplexer时如何注入ILogger呢?