Files
MegghysAPI/Program.cs
Megghy b2c648c3e6 迁移到 Ant Design 并优化 DNS 接口
将项目从 Fluent UI 迁移到 Ant Design Blazor:
- 替换 UI 组件,更新样式和脚本。
- 移除 Fluent UI 相关依赖,添加 Ant Design 依赖。

优化 DNS 解析接口:
- 将解析接口从 POST 改为 GET,简化参数结构。
- 更新 `DnsResponse` 和配置文件结构。

数据库模型优化:
- 为 JSON 数据存储添加 `JArray` 映射支持。

初始化逻辑重构:
- 简化 `AutoInit` 初始化逻辑,提升代码可读性。

其他改动:
- 升级依赖包版本。
- 移除无用命名空间和属性。
2025-09-25 17:15:57 +08:00

84 lines
2.1 KiB
C#

using System.Diagnostics;
using System.Reflection;
using MegghysAPI.Attributes;
using MegghysAPI.Components;
using AntDesign;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddAntDesign();
builder.Services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.UseRouting();
app.UseAntiforgery();
app.MapControllers();
// 加载所有有 AutoInitAttribute 的类
// 获取当前Assembly
var inits = new List<MethodInfo>();
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
{
foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)
.Where(m => m.GetCustomAttribute<AutoInitAttribute>() is not null))
{
inits.Add(method);
}
}
DB.InitDB();
inits = inits
.OrderBy(m => m.GetCustomAttribute<AutoInitAttribute>()?.Order ?? 0)
.ToList();
foreach (var method in inits)
{
var sw = Stopwatch.StartNew();
var attr = method.GetCustomAttribute<AutoInitAttribute>();
if (attr?.LogMessage is { } message)
{
Logs.Info(message);
}
if (attr?.Async is true)
{
_ = Task.Run(() =>
{
method.Invoke(null, null);
attr.PostInit?.Invoke();
Logs.Info($"[{sw.ElapsedMilliseconds} ms] Async <{method.DeclaringType?.Name}.{method.Name}> => Inited.");
});
}
else
{
method.Invoke(null, null);
attr?.PostInit?.Invoke();
Logs.Info($"[{sw.ElapsedMilliseconds} ms] <{method.DeclaringType?.Name}.{method.Name}> => Inited.");
}
}
app.Run();