-
Notifications
You must be signed in to change notification settings - Fork 9
/
App.xaml.cs
100 lines (79 loc) · 3.39 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using DarkMode_2.Services;
using DarkMode_2.ViewModels;
using DarkMOde_2.Services;
using DarkMOde_2.Services.Contracts;
using log4net.Config;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;
using System.Reflection;
using System.Windows;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services;
using WPFLocalizeExtension.Engine;
namespace DarkMode_2;
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App
{
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
.ConfigureServices((context, services) =>
{
// 注册程序实例
services.AddHostedService<ApplicationHostService>();
// 注册主题实例
services.AddSingleton<IThemeService, ThemeService>();
// 注册任务栏操作实例
services.AddSingleton<ITaskBarService, TaskBarService>();
// 注册弹窗实例
services.AddSingleton<ISnackbarService, SnackbarService>();
// 注册命令行参数实例
//services.AddSingleton<IEnvironmentService, Services.Contracts.MyProductionEnvironmentService>();
// 注册对话服务实例
services.AddSingleton<IDialogService, DialogService>();
// 窗口页面解析
services.AddSingleton<IPageService, PageService>();
services.AddSingleton<ITestWindowService, TestWindowService>();
// 注册Navigation实例
services.AddSingleton<INavigationService, NavigationService>();
// 注册启动窗口实例
services.AddScoped<INavigationWindow, Views.MainWindow>();
services.AddScoped<MainWindowViewModel>();
// 注册Page页面实例
services.AddScoped<Views.Pages.SetTimes>();
services.AddScoped<Views.Pages.SetAbout>();
services.AddScoped<Views.Pages.SetDIY>();
services.AddScoped<Views.Pages.SetMore>();
services.AddScoped<Views.Pages.SetSetting>();
services.AddScoped<Views.Pages.SetWallpaper>();
services.AddScoped<SetTimesViewModel>();
services.AddScoped<SetAboutViewModel>();
services.AddScoped<SetDIYViewModel>();
services.AddScoped<SetMoreViewModel>();
services.AddScoped<SetSettingViewModel>();
services.AddScoped<SetWallpaperViewModel>();
// 注册窗口及模型实例
services.AddTransient<Views.SettingsWindow>();
services.AddTransient<SettingsViewModel>();
services.AddTransient<Views.DeveloperModeWindow>();
services.AddTransient<DeveloperModeViewModel>();
services.AddTransient<Views.DownloadWindow>();
services.AddTransient<DownloadWindowViewModel>();
}).Build();
private async void OnStartup(object sender, StartupEventArgs e)
{
XmlConfigurator.Configure();
string logDirectory = Path.Combine(Path.GetTempPath(), "DarkMode2", "logs");
if (!Directory.Exists(logDirectory))
{
Directory.CreateDirectory(logDirectory);
}
//启动程序入口
await _host.StartAsync();
}
}