Phase 0: 项目初始化与基础架构
- 创建 .NET 8 WPF 项目 PersonalToolBox - 引入 NuGet 包: CommunityToolkit.Mvvm, System.Text.Json, Microsoft.Extensions.DependencyInjection - 建立 MVVM 目录结构: Models/ ViewModels/ Views/ Services/ Helpers/ - 实现 LogEntry 模型 (时间/日志级别/内容) - 实现 ILogService 接口与 LogService (线程安全, 通过 Dispatcher 推送到 UI) - 配置 DI 容器 (App.xaml.cs) 注册日志服务和主窗口 - 添加 .gitignore 文件
This commit is contained in:
38
PersonalToolBox/App.xaml.cs
Normal file
38
PersonalToolBox/App.xaml.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Windows;
|
||||
using PersonalToolBox.Services;
|
||||
using PersonalToolBox.Views;
|
||||
|
||||
namespace PersonalToolBox;
|
||||
|
||||
/// <summary>
|
||||
/// WPF 应用程序入口,负责依赖注入容器初始化和启动主窗口
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public static IServiceProvider Services { get; private set; } = null!;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
Services = services.BuildServiceProvider();
|
||||
|
||||
var mainWindow = Services.GetRequiredService<MainWindow>();
|
||||
mainWindow.Show();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册所有服务到 DI 容器(单例模式)
|
||||
/// </summary>
|
||||
private static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// 日志服务
|
||||
services.AddSingleton<ILogService, LogService>();
|
||||
|
||||
// 主窗口
|
||||
services.AddSingleton<MainWindow>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user