mirror of
https://github.com/Megghy/MegghysAPI.git
synced 2025-12-06 14:16:56 +08:00
添加项目文件。
This commit is contained in:
68
Program.cs
Normal file
68
Program.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using MegghysAPI.Attributes;
|
||||
using MegghysAPI.Components;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
builder.Services.AddFluentUIComponents();
|
||||
|
||||
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.MapControllers();
|
||||
app.MapBlazorHub();
|
||||
app.MapFallbackToPage("/_Host");
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> AutoInitAttribute <20><><EFBFBD><EFBFBD>
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰAssembly
|
||||
var inits = new List<MethodInfo>();
|
||||
Assembly.GetExecutingAssembly()
|
||||
.GetTypes()
|
||||
.ForEach(t => t.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)
|
||||
.Where(m => m.GetCustomAttribute<AutoInitAttribute>() is { }).ForEach(m => inits.Add(m)));
|
||||
inits = [.. inits.OrderBy(m => m.GetCustomAttribute<AutoInitAttribute>().Order)];
|
||||
inits.ForEach(m =>
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var attr = m.GetCustomAttribute<AutoInitAttribute>();
|
||||
if (attr.LogMessage is not null)
|
||||
Logs.Info(attr.LogMessage);
|
||||
if (attr.Async)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
m.Invoke(null, null);
|
||||
attr.PostInit?.Invoke();
|
||||
Logs.Info($"[{sw.ElapsedMilliseconds} ms] Async <{m.DeclaringType.Name}.{m.Name}> => Inited.");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
m.Invoke(null, null);
|
||||
attr.PostInit?.Invoke();
|
||||
Logs.Info($"[{sw.ElapsedMilliseconds} ms] <{m.DeclaringType.Name}.{m.Name}> => Inited.");
|
||||
}
|
||||
});
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user