Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIC 定义从可继承仓库里读取的逻辑 #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task<string> TryReadAsync(string key, string @default = "")
VerifyKey(key);

var value = await ReadValueCoreAsync(key).ConfigureAwait(false);
return value ?? @default;
return value ?? ReadFromInheritedConfigurationRepo() ?? @default;
}

/// <summary>
Expand Down Expand Up @@ -135,6 +135,17 @@ public async Task WriteAsync(string key, string? value)
#pragma warning restore 4014
}

/// <summary>
/// 加上配置继承的仓库
/// </summary>
/// <param name="configurationRepo"></param>
public void AddInheritedConfigurationRepo(IReadOnlyConfigurationRepo configurationRepo)
{

}

private string? ReadFromInheritedConfigurationRepo() => null;

private async Task NotifyChanged(IEnumerable<string> keys)
{
var context = new AsynchronousConfigurationChangeContext(keys);
Expand Down
10 changes: 1 addition & 9 deletions src/dotnetCampus.Configurations/Core/IConfigurationRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@ namespace dotnetCampus.Configurations.Core
/// <summary>
/// 管理应用程序中的字符串配置项。
/// </summary>
public interface IConfigurationRepo
public interface IConfigurationRepo : IReadOnlyConfigurationRepo
{
/// <summary>
/// 创建一个使用强类型的用于提供给应用程序业务使用的应用程序配置管理器。
/// </summary>
/// <returns>用于提供给应用程序业务使用的配置管理器。</returns>
IAppConfigurator CreateAppConfigurator();

/// <summary>
/// 获取指定配置项的值,如果指定的 <paramref name="key"/> 不存在,则返回 null。
/// 此方法是线程安全的。
/// </summary>
/// <param name="key">配置项的标识符。</param>
/// <returns>配置项的值。</returns>
string? GetValue(string key);

/// <summary>
/// 设置指定配置项的值,如果设置为 null,可能删除 <paramref name="key"/> 配置项。
/// 此方法是线程安全的。
Expand Down
16 changes: 16 additions & 0 deletions src/dotnetCampus.Configurations/Core/IReadOnlyConfigurationRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace dotnetCampus.Configurations.Core
{
/// <summary>
/// 表示这是一个只读的配置仓库
/// </summary>
public interface IReadOnlyConfigurationRepo
{
/// <summary>
/// 获取指定配置项的值,如果指定的 <paramref name="key"/> 不存在,则返回 null。
/// 此方法是线程安全的。
/// </summary>
/// <param name="key">配置项的标识符。</param>
/// <returns>配置项的值。</returns>
string? GetValue(string key);
}
}