应用程序初始化配置文件 ProgramWebApplication.cs
//Path.Combine(AppContext.BaseDirectory, "Config")
var env = EnvPFUtil.CurrentEnv(); // Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var os = EnvPFUtil.CurrentSystemName();
var configBuilderDebug = new ConfigurationBuilder()
.SetBasePath(PhyPathUtil.ConvertVirToPhyPath("~/Config")).AddJsonFile($"debug.provider.json", optional: false, reloadOnChange: true);
var configDebug = configBuilderDebug.Build();
bool debug = configDebug.GetValue<bool>("debug:start");
var configBuilder = new ConfigurationBuilder()
.SetBasePath(PhyPathUtil.ConvertVirToPhyPath("~/Config"));
//应用主机信息
LoadAppConfig("hosting", configSetup, env, os, debug, configBuilder);
//应用框架信息
LoadAppConfig("framework", configSetup, env, os, debug, configBuilder);
//基础配置信息
LoadAppConfig("app", configSetup, env, os, debug, configBuilder);
//扩展的业务信息
LoadAppConfig("business", configSetup, env, os, debug, configBuilder);
//添加guid使用雪花算法
LoadAppConfig("snowflake.provider", configSetup, env, os, debug, configBuilder);
//数据库信息
LoadAppConfig("db.provider", configSetup, env, os, debug, configBuilder);
//代理信息
LoadAppConfig("proxy.reflection", configSetup, env, os, debug, configBuilder);
//白名单限流信息
LoadAppConfig("ip.rate.limit.policy", configSetup, env, os, debug, configBuilder);
//缓存配置
LoadAppConfig("mapper.cache.provider", configSetup, env, os, debug, configBuilder);
//mapper路径
LoadAppConfig("mapper.path.provider", configSetup, env, os, debug, configBuilder);
//控制调试工具类
LoadAppConfig("debug.provider", configSetup, env, os, debug, configBuilder);
//redis
LoadAppConfig("redis.provider", configSetup, env, os, debug, configBuilder);
//mongodb
LoadAppConfig("mongodb.provider", configSetup, env, os, debug, configBuilder);
//elasticsearc
LoadAppConfig("elasticsearch.provider", configSetup, env, os, debug, configBuilder);
//kafaka
LoadAppConfig("kafaka.provider", configSetup, env, os, debug, configBuilder);
//rabbitmq
LoadAppConfig("rabbitmq.provider", configSetup, env, os, debug, configBuilder);
//messageq 消息队列
LoadAppConfig("messageq.provider", configSetup, env, os, debug, configBuilder);
//cache 缓存
LoadAppConfig("cache.provider", configSetup, env, os, debug, configBuilder);
//任务调度信息
LoadAppConfig("quartz.provider", configSetup, env, os, debug, configBuilder);
//IFileProvider
//添加 多数据模板配置加载,便于提高性能
string phyMapperApp = PhyPathUtil.ConvertVirToPhyPath($"~/Config/MapperApp");
if (FileUtil.ExistsDirByVirPath(phyMapperApp))
{
IFileProvider _fileProviderT = new PhysicalFileProvider(phyMapperApp);
foreach (IFileInfo item in _fileProviderT.GetDirectoryContents(""))
{
if (!item.IsDirectory && item.PhysicalPath.Contains("mapper_template_"))
{
configBuilder.AddJsonFile($"MapperApp/{item.Name}", optional: false, reloadOnChange: true);
if (debug)
{
try
{
configSetup?.Invoke(configBuilder); configBuilder.Build();
}
catch (Exception)
{
throw new Exception($"MapperApp/{item.Name}格式错误");
}
}
}
}
}
//添加 多数据模板配置加载,便于提高性能
string phyAppGlobal = PhyPathUtil.ConvertVirToPhyPath($"~/Config/AppGlobal");
if (FileUtil.ExistsDirByVirPath(phyAppGlobal))
{
IFileProvider _glogalProviderT = new PhysicalFileProvider(phyAppGlobal);
foreach (IFileInfo item in _glogalProviderT.GetDirectoryContents(""))
{
if (item.IsDirectory)
{
foreach (IFileInfo itemC in _glogalProviderT.GetDirectoryContents(item.Name))
{
if (itemC.Name.EndsWith(".json"))
{
configBuilder.AddJsonFile($"AppGlobal/{item.Name}/{itemC.Name}", optional: true, reloadOnChange: true);
if (debug)
{
try
{
configSetup?.Invoke(configBuilder); configBuilder.Build();
}
catch (Exception)
{
throw new Exception($"AppGlobal/{item.Name}/{itemC.Name}格式错误");
}
}
configBuilder.AddJsonFile($"AppGlobal/{item.Name}/{itemC.Name.Replace(".json", "")}.{env ?? "Production"}.json", optional: true, reloadOnChange: true);
if (debug)
{
try
{
configSetup?.Invoke(configBuilder); configBuilder.Build();
}
catch (Exception)
{
throw new Exception($"AppGlobal/{item.Name}/{itemC.Name.Replace(".json", "")}.{env ?? "Production"}.json格式错误");
}
}
configBuilder.AddJsonFile($"AppGlobal/{item.Name}/{itemC.Name}.{os}.json", optional: true, reloadOnChange: true);
if (debug)
{
try
{
configSetup?.Invoke(configBuilder); configBuilder.Build();
}
catch (Exception)
{
throw new Exception($"AppGlobal/{item.Name}/{itemC.Name.Replace(".json", "")}.{os}.json格式错误");
}
}
}
}
}
}
}
configBuilder.AddEnvironmentVariables();
configSetup?.Invoke(configBuilder);
var config = configBuilder.Build();
文档更新时间: 2021-09-13 08:27 作者:admin