Files
Kg.SeaTime/Service/Application.Web/Program.cs
Putoo 784bc66ef6 111
2026-05-20 18:32:54 +08:00

126 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.OpenApi.Models;
using Photon.Core.Redis;
var builder = WebApplication.CreateBuilder(args);
builder.Services.Inject(new List<string> {
"Application.Web","Application.Domain"
});//框架初始化
builder.Configuration.RegisterConfig();//注入配置
builder.Services.InjectRedis(builder.Configuration);
builder.Services.InjectSql(builder.Configuration);
#region JWT与接口配置
Dictionary<string, OpenApiInfo> groups = new Dictionary<string, OpenApiInfo>();
groups.Add("Login", new OpenApiInfo
{
Title = "登录接口文档",
Version = "v1",
Description = "航海时代登录相关接口。",
});
groups.Add("User", new OpenApiInfo
{
Title = "用户接口文档",
Version = "v1",
Description = "航海时代用户相关接口。",
});
groups.Add("Map", new OpenApiInfo
{
Title = "用户地图文档",
Version = "v1",
Description = "航海时代用户地图相关接口。",
});
builder.Services.InjectJwt(builder.Configuration, new OpenApiInfo
{
Title = "航海时代接口文档",
Version = "v1",
Description = "航海时代接口文档包含航海时代的所有接口项目采用AI开发。",
}, "Application.Web", op =>
{
op.AddTransient<IJwtValidator, Application.Web.JwtHandle>();
}, groups);
#endregion
//定时功能
builder.Services.InjectTimer(services =>
{
services.AddTransient<ITimerJobManager, TimerJobManager>();//注册管理器
services.AddSingleton<AutoJob>();
services.AddHostedService<JobStart>();
});
//日志
builder.Logging.InjectLog();
// Add services to the container.
builder.Services.AddControllers().AddJsonOptions(option =>
{
option.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
option.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
option.JsonSerializerOptions.MaxDepth =int.MaxValue;
});
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
#region
builder.Services.AddCors(options =>
{
options.AddPolicy("all", builder =>
{
builder.AllowAnyOrigin() //允许任何来源的主机访问
.AllowAnyMethod()
.AllowAnyHeader();
});
});
#endregion
builder.Services.AddSignalR();
var app = builder.Build();
app.Services.UseInject();//启用框架
app.Configuration.UseConfig();//启用配置
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
#region swagger配置
app.UseJwtSwagger("swagger", "航海时代接口文档",new List<JwtGroupConfig> {
new JwtGroupConfig(){ groupId="Login", groupName="登录接口文档"},
new JwtGroupConfig(){ groupId="User", groupName="用户接口文档"},
new JwtGroupConfig(){ groupId="Map", groupName="用户地图文档"}
});
#endregion
}
app.UseCors("all");
app.UseStaticFiles();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapHub<ChatHub>("/chatHub");
app.MapControllers();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
SnowflakeAssist.Initialize(0, 0);
app.Run();