我正在使用.NET Core 3.1和 Docker 机密来存储敏感的配置数据。我正在使用AddKeyPerFile
扩展方法告诉 .NET Core 从文件系统上的文件中加载键值对。我想设置directoryPath
这些文件的位置并IgnoreCondition
忽略特定文件。但是,KeyPerFileConfigurationBuilderExtensions
只包含以下两种方法:
public static IConfigurationBuilder AddKeyPerFile(this IConfigurationBuilder builder, Action<KeyPerFileConfigurationSource> configureSource);
public static IConfigurationBuilder AddKeyPerFile(this IConfigurationBuilder builder, string directoryPath, bool optional);
...并KeyPerFileConfigurationSource
包含以下属性:
public IFileProvider FileProvider { get; set; }
public Func<string, bool> IgnoreCondition { get; set; }
public string IgnorePrefix { get; set; }
public bool Optional { get; set; }
这是我目前拥有的代码:
ConfigurationBuilder cb = new ConfigurationBuilder();
// I want to set 'IgnoreCondition' as well
cb.AddKeyPerFile(directoryPath: "/abc123", optional: true);
如何同时设置directoryPath
AND IgnoreCondition
?