Learn.Archives/Learn.Archives.API/Program.cs

72 lines
2.0 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 Learn.Archives.Core.Common;
using Microsoft.OpenApi.Models;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using Learn.Archives.Core.Common.Expand;
using Mapster;
using System.Text.Json;
using Learn.Archives.API.Expand;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.ClearProviders(); // 清除默认的日志提供程序
loggingBuilder.AddConsole(); // 添加控制台日志提供程序
loggingBuilder.SetMinimumLevel(LogLevel.Warning); // 设置最小日志级别为 Warning
});
builder.Services.AddControllers(options =>
{
// 全局模型赋值默认值 和 统一返回格式处理
options.Filters.Add<HttpLogAttribute>();
})
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);//中文转换时不使用Unicode
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;// 默认小驼峰 null 大驼峰
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Description = "学校档案系统v1"
});
var file = Path.Combine(AppContext.BaseDirectory, "Learn.Archives.API.xml"); // xml文档绝对路径
c.IncludeXmlComments(file, true); // true : 显示控制器层注释
c.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序如果有多个就可以看见效果了。
});
builder.Configuration.AddAppConfig(args);
builder.Services.AddPermissionAuthentication();
builder.Services.AddSqlSugarExpand();
builder.Services.AddRedisExpand();
builder.Services.AddCorsExpand();
builder.Services.AddMapster();
builder.Services.AddLiveUserInfoExpand();
builder.Services.AddHttpClient();
builder.Services.AddHttpContextAccessor();
var app = builder.Build();
app.UseMiddleware<BasicAuthMiddleware>("Swagger");
app.UseSwagger();
app.UseSwaggerUI();
//自定义 应用
app.UseCorsExpand();
app.UseSqlSugarExpand();
app.UseAuthorization();
app.MapControllers();
app.Run();