2026-04-23 16:23:40 +08:00
|
|
|
|
using Avalonia;
|
2026-05-11 14:35:34 +08:00
|
|
|
|
using Avalonia_Common.Infrastructure;
|
|
|
|
|
|
using Avalonia_EFCore.Database;
|
2026-04-24 11:56:02 +08:00
|
|
|
|
using Avalonia_PC.Views;
|
2026-05-11 14:35:34 +08:00
|
|
|
|
using Avalonia_Services.Core;
|
|
|
|
|
|
using Avalonia_Services.Database;
|
|
|
|
|
|
using Avalonia_Services.Endpoints;
|
2026-04-24 11:56:02 +08:00
|
|
|
|
using Avalonia_Services.Services;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-05-11 14:35:34 +08:00
|
|
|
|
using Serilog;
|
2026-04-23 16:23:40 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Avalonia_PC
|
|
|
|
|
|
{
|
|
|
|
|
|
internal sealed class Program
|
|
|
|
|
|
{
|
2026-04-24 11:56:02 +08:00
|
|
|
|
public static IServiceProvider Services { get; private set; } = null!;
|
|
|
|
|
|
|
2026-04-23 16:23:40 +08:00
|
|
|
|
[STAThread]
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
|
{
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// 初始化日志系统
|
|
|
|
|
|
AppLog.Initialize(LoggingConfiguration.CreateDefaultLogger(logDir: "logs"));
|
|
|
|
|
|
|
|
|
|
|
|
AppLog.Information("Avalonia-PC 正在启动...");
|
|
|
|
|
|
|
2026-04-24 11:56:02 +08:00
|
|
|
|
ConfigureServices();
|
|
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// 初始化数据库(自动迁移 + 种子数据)
|
|
|
|
|
|
Services.InitializeDatabase<AppDataContext>();
|
|
|
|
|
|
|
|
|
|
|
|
// 启动时打印所有拦截的接口
|
|
|
|
|
|
var endpoints = Services.GetRequiredService<ServiceEndpointCollection>();
|
|
|
|
|
|
EndpointPrinter.PrintEndpoints(endpoints, "Avalonia-PC 拦截接口列表");
|
|
|
|
|
|
|
2026-04-23 16:23:40 +08:00
|
|
|
|
#if DEBUG
|
|
|
|
|
|
// 开启 WebView2 远程调试,启动后在 Edge 中访问 edge://inspect 调试网页
|
|
|
|
|
|
Environment.SetEnvironmentVariable(
|
|
|
|
|
|
"WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS",
|
|
|
|
|
|
"--remote-debugging-port=9222 --auto-open-devtools-for-tabs");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-24 11:56:02 +08:00
|
|
|
|
private static void ConfigureServices()
|
|
|
|
|
|
{
|
|
|
|
|
|
var services = new ServiceCollection();
|
2026-05-11 14:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
// ---- 数据库 ----
|
|
|
|
|
|
// 注册默认数据库提供程序(SQLite / MySQL / PostgreSQL / SqlServer)
|
|
|
|
|
|
DatabaseProviderRegistry.RegisterDefaults();
|
|
|
|
|
|
|
|
|
|
|
|
// 桌面端固定使用 SQLite 本地数据库
|
|
|
|
|
|
services.AddAppDatabase<AppDataContext>(DatabaseConfiguration.ForSQLite("app.db"));
|
|
|
|
|
|
|
|
|
|
|
|
// ---- 业务服务 ----
|
2026-04-24 11:56:02 +08:00
|
|
|
|
services.AddSingleton<WeatherForecastService>();
|
2026-05-11 14:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
// ---- 统一端点 ----
|
|
|
|
|
|
var endpointBuilder = new ServiceEndpointBuilder();
|
|
|
|
|
|
AppEndpoints.Configure(endpointBuilder);
|
|
|
|
|
|
var endpoints = endpointBuilder.Build();
|
|
|
|
|
|
services.AddSingleton(endpoints);
|
|
|
|
|
|
|
|
|
|
|
|
// 注册 Window
|
2026-04-24 11:56:02 +08:00
|
|
|
|
services.AddTransient<MainWindow>(sp => new MainWindow(sp));
|
2026-04-23 16:23:40 +08:00
|
|
|
|
|
2026-04-24 11:56:02 +08:00
|
|
|
|
Services = services.BuildServiceProvider();
|
|
|
|
|
|
}
|
2026-04-23 16:23:40 +08:00
|
|
|
|
|
|
|
|
|
|
// Avalonia configuration, don't remove; also used by visual designer.
|
|
|
|
|
|
public static AppBuilder BuildAvaloniaApp()
|
|
|
|
|
|
=> AppBuilder.Configure<App>()
|
|
|
|
|
|
.UsePlatformDetect()
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
.WithDeveloperTools()
|
|
|
|
|
|
#endif
|
|
|
|
|
|
.WithInterFont()
|
|
|
|
|
|
.LogToTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|