diff --git a/src/dotnetCampus.Configurations/Core/AsynchronousConfigurationRepo.cs b/src/dotnetCampus.Configurations/Core/AsynchronousConfigurationRepo.cs index 0498d48..5064a96 100644 --- a/src/dotnetCampus.Configurations/Core/AsynchronousConfigurationRepo.cs +++ b/src/dotnetCampus.Configurations/Core/AsynchronousConfigurationRepo.cs @@ -99,7 +99,7 @@ public async Task TryReadAsync(string key, string @default = "") VerifyKey(key); var value = await ReadValueCoreAsync(key).ConfigureAwait(false); - return value ?? @default; + return value ?? ReadFromInheritedConfigurationRepo() ?? @default; } /// @@ -135,6 +135,17 @@ public async Task WriteAsync(string key, string? value) #pragma warning restore 4014 } + /// + /// 加上配置继承的仓库 + /// + /// + public void AddInheritedConfigurationRepo(IReadOnlyConfigurationRepo configurationRepo) + { + + } + + private string? ReadFromInheritedConfigurationRepo() => null; + private async Task NotifyChanged(IEnumerable keys) { var context = new AsynchronousConfigurationChangeContext(keys); diff --git a/src/dotnetCampus.Configurations/Core/IConfigurationRepo.cs b/src/dotnetCampus.Configurations/Core/IConfigurationRepo.cs index f99f47d..98d3b35 100644 --- a/src/dotnetCampus.Configurations/Core/IConfigurationRepo.cs +++ b/src/dotnetCampus.Configurations/Core/IConfigurationRepo.cs @@ -5,7 +5,7 @@ namespace dotnetCampus.Configurations.Core /// /// 管理应用程序中的字符串配置项。 /// - public interface IConfigurationRepo + public interface IConfigurationRepo : IReadOnlyConfigurationRepo { /// /// 创建一个使用强类型的用于提供给应用程序业务使用的应用程序配置管理器。 @@ -13,14 +13,6 @@ public interface IConfigurationRepo /// 用于提供给应用程序业务使用的配置管理器。 IAppConfigurator CreateAppConfigurator(); - /// - /// 获取指定配置项的值,如果指定的 不存在,则返回 null。 - /// 此方法是线程安全的。 - /// - /// 配置项的标识符。 - /// 配置项的值。 - string? GetValue(string key); - /// /// 设置指定配置项的值,如果设置为 null,可能删除 配置项。 /// 此方法是线程安全的。 diff --git a/src/dotnetCampus.Configurations/Core/IReadOnlyConfigurationRepo.cs b/src/dotnetCampus.Configurations/Core/IReadOnlyConfigurationRepo.cs new file mode 100644 index 0000000..6271b01 --- /dev/null +++ b/src/dotnetCampus.Configurations/Core/IReadOnlyConfigurationRepo.cs @@ -0,0 +1,16 @@ +namespace dotnetCampus.Configurations.Core +{ + /// + /// 表示这是一个只读的配置仓库 + /// + public interface IReadOnlyConfigurationRepo + { + /// + /// 获取指定配置项的值,如果指定的 不存在,则返回 null。 + /// 此方法是线程安全的。 + /// + /// 配置项的标识符。 + /// 配置项的值。 + string? GetValue(string key); + } +}