增加IConfiguration扩展方法RegisterReload,当配置文件发生变化时执行reload方法。
This commit is contained in:
parent
3c08f01c19
commit
b3772ba78d
21
Falcon.SugarApi/IConfigurationExtend.cs
Normal file
21
Falcon.SugarApi/IConfigurationExtend.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
|
||||
namespace Falcon.SugarApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置扩展方法
|
||||
/// </summary>
|
||||
public static class IConfigurationExtend
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册支持注册配置重载事件。当配置文件发生变化时候执行重载回调
|
||||
/// </summary>
|
||||
/// <param name="config">配置对象</param>
|
||||
/// <param name="reload">当配置文件发生变化时候执行的回调</param>
|
||||
public static void RegisterReload(this IConfiguration config,Action<IConfiguration> reload) {
|
||||
reload(config);
|
||||
config.GetReloadToken().RegisterChangeCallback(a => config.RegisterReload(reload),config);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user