110 lines
3.9 KiB
C#
110 lines
3.9 KiB
C#
|
|
|
|||
|
|
using FluentValidation;
|
|||
|
|
using Mapster;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using NewLife;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Windows;
|
|||
|
|
using YY.Admin.Core;
|
|||
|
|
using YY.Admin.EventBus;
|
|||
|
|
using YY.Admin.Filter;
|
|||
|
|
using YY.Admin.Module;
|
|||
|
|
using YY.Admin.Properties;
|
|||
|
|
using YY.Admin.Setup;
|
|||
|
|
using YY.Admin.ViewModels;
|
|||
|
|
using YY.Admin.Views;
|
|||
|
|
namespace YY.Admin
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Interaction logic for App.xaml
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class App : PrismApplication
|
|||
|
|
{
|
|||
|
|
private IConfiguration? _configuration;
|
|||
|
|
private ILoggerService? _logger;
|
|||
|
|
private readonly SyncModule _syncModule = new();
|
|||
|
|
protected override Window CreateShell()
|
|||
|
|
{
|
|||
|
|
return Container.Resolve<LoginWindow>();
|
|||
|
|
}
|
|||
|
|
protected override void OnStartup(StartupEventArgs e)
|
|||
|
|
{
|
|||
|
|
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
|||
|
|
// 构建配置
|
|||
|
|
_configuration = new ConfigurationBuilder()
|
|||
|
|
.SetBasePath(baseDirectory)
|
|||
|
|
.AddJsonFile("Configuration/appsettings.json", optional: false, reloadOnChange: true)
|
|||
|
|
.Build();
|
|||
|
|
// 全局配置
|
|||
|
|
TypeAdapterConfig.GlobalSettings.Default
|
|||
|
|
.IgnoreNullValues(true)
|
|||
|
|
.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);
|
|||
|
|
|
|||
|
|
// FluentValidation 全局规则级别配置
|
|||
|
|
ValidatorOptions.Global.DefaultRuleLevelCascadeMode = CascadeMode.Stop;
|
|||
|
|
|
|||
|
|
// Mapster 全局配置
|
|||
|
|
#if DEBUG
|
|||
|
|
//TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true;
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
base.OnStartup(e);
|
|||
|
|
}
|
|||
|
|
//注册
|
|||
|
|
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
|||
|
|
{
|
|||
|
|
//后续调整为配置依赖注入(Prism Module)
|
|||
|
|
// 注册错误处理
|
|||
|
|
containerRegistry.RegisterSingleton<IErrorHandler, ErrorHandler>();
|
|||
|
|
//全局错误处理
|
|||
|
|
containerRegistry.RegisterSingleton<GlobalExceptionHandler>();
|
|||
|
|
|
|||
|
|
// 注册事件聚合器(Prism自带)
|
|||
|
|
containerRegistry.RegisterSingleton<IEventAggregator, EventAggregator>();
|
|||
|
|
|
|||
|
|
//项目配置选项
|
|||
|
|
containerRegistry.AddProjectOptions(_configuration!);
|
|||
|
|
// 注册原始配置,供业务服务读取第三方对接参数
|
|||
|
|
containerRegistry.RegisterInstance(_configuration!);
|
|||
|
|
// 注册缓存服务
|
|||
|
|
containerRegistry.AddNewLifeCache(_configuration!);
|
|||
|
|
//注册数据库服务
|
|||
|
|
containerRegistry.AddDbContext(_configuration!);
|
|||
|
|
//注册通知事件服务
|
|||
|
|
containerRegistry.AddNotificationEventBus();
|
|||
|
|
// 服务注册
|
|||
|
|
containerRegistry.AddService(_configuration!);
|
|||
|
|
// 注册HttpClient连接池
|
|||
|
|
containerRegistry.AddHttpClient();
|
|||
|
|
|
|||
|
|
// 注册断联续传同步模块
|
|||
|
|
_syncModule.RegisterTypes(containerRegistry);
|
|||
|
|
|
|||
|
|
// 注册所有需要导航的视图
|
|||
|
|
containerRegistry.AddNavigation();
|
|||
|
|
}
|
|||
|
|
protected override void OnInitialized()
|
|||
|
|
{
|
|||
|
|
base.OnInitialized();
|
|||
|
|
// 获取日志服务
|
|||
|
|
_logger = Container.Resolve<ILoggerService>();
|
|||
|
|
// 初始化全局异常处理(通过解析触发构造函数注册)
|
|||
|
|
Container.Resolve<GlobalExceptionHandler>();
|
|||
|
|
// 保存默认主题
|
|||
|
|
AppSettings.Default.SkinType = AppSettingsViewModel.GetSkinType().ToInt();
|
|||
|
|
AppSettings.Default.Save();
|
|||
|
|
|
|||
|
|
_logger.Information("应用程序已启动");
|
|||
|
|
|
|||
|
|
// 启动断联续传同步模块
|
|||
|
|
_syncModule.OnInitialized(Container);
|
|||
|
|
}
|
|||
|
|
protected override void OnExit(ExitEventArgs e)
|
|||
|
|
{
|
|||
|
|
BaseViewModel.StopTokenCheckTimer();
|
|||
|
|
base.OnExit(e);
|
|||
|
|
_logger?.Information("应用程序已退出");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|