项目应用程序配置(Program.cs)
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true)
.AddEnvironmentVariables();
//从Consul中加载配置
builder.Configuration.AddConsulConfiguration(builder.Configuration);
var services = builder.Services;
//加载配置到全局
GlobalHelper.LoadConfiguration(builder.Configuration);
services.ConfigureHttpClients("HttpClientInfos");
//系统所需配置
services.ConfigureVerify<CommonInfo>();
services.ConfigureVerify<SystemInfo>();
services.ConfigureVerify<RedisInfo>();
services.ConfigureVerify<DatabaseInfo>();
services.ConfigureVerify<LocalUploadInfo>();
//指定json中别名
services.ConfigureVerify<List<AllowUploadFile>>("AllowUploadFiles");
//配置中心及服务与发现
if (commonInfo.ServiceDiscoveryConfig != null)
{
services.AddConsul(commonInfo.ServiceDiscoveryConfig.BaseUrl, commonInfo.ServiceDiscoveryConfig.CacheInterval);
}
//项目实例和租户的事件总线
services.AddSingleton(provider =>
{
var eventBus = new BaseEventBus();
eventBus.Subscribe(EventHelper.HandleTenant);
eventBus.Subscribe(EventHelper.HandleProjectExample);
return eventBus;
});