添加项目文件。
This commit is contained in:
87
MoviconWebApi/Program.cs
Normal file
87
MoviconWebApi/Program.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
|
||||
using FastEndpoints;
|
||||
using FastEndpoints.Security;
|
||||
using FastEndpoints.Swagger;
|
||||
|
||||
namespace MoviconWebApi
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
//builder.Services.AddAuthorization();
|
||||
|
||||
// 配置FreeSql
|
||||
var connectionString = builder.Configuration.GetConnectionString("SqlServer");
|
||||
var freeSql = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.SqlServer, connectionString)
|
||||
.UseAutoSyncStructure(true) // 开发环境下自动同步实体结构到数据库
|
||||
.UseMonitorCommand(cmd => Console.WriteLine($"SQL:{cmd.CommandText}")) // 监控SQL语句(开发环境用)
|
||||
.Build();
|
||||
// 注册FreeSql为单例服务
|
||||
builder.Services.AddSingleton<IFreeSql>(freeSql);
|
||||
|
||||
// 配置JWT认证
|
||||
builder.Services.AddAuthenticationJwtBearer(o => o.SigningKey = builder.Configuration["JwtSigningKey"]);
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddFastEndpoints();
|
||||
builder.Services.SwaggerDocument(o =>
|
||||
{
|
||||
o.DocumentSettings = s =>
|
||||
{
|
||||
s.Title = "Movicon Web API";
|
||||
s.Version = "v1";
|
||||
s.Description = "MoviconHub 数据访问API";
|
||||
};
|
||||
});
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
//builder.Services.AddEndpointsApiExplorer();
|
||||
//builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
//注意:FastEndpoints有自己的Swagger配置,不需要使用原生的UseSwagger和UseSwaggerUI
|
||||
//if (app.Environment.IsDevelopment())
|
||||
//{
|
||||
// app.UseSwagger();
|
||||
// app.UseSwaggerUI();
|
||||
//}
|
||||
|
||||
app.UseAuthentication()
|
||||
.UseAuthorization()
|
||||
.UseFastEndpoints(c =>
|
||||
{
|
||||
c.Serializer.Options.PropertyNamingPolicy = null; // 保持属性名不变
|
||||
c.Endpoints.RoutePrefix = "api"; // 设置API路由前缀
|
||||
})
|
||||
.UseSwaggerGen();
|
||||
|
||||
var summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
//app.MapGet("/weatherforecast", (HttpContext httpContext) =>
|
||||
//{
|
||||
// var forecast = Enumerable.Range(1, 5).Select(index =>
|
||||
// new WeatherForecast
|
||||
// {
|
||||
// Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
// TemperatureC = Random.Shared.Next(-20, 55),
|
||||
// Summary = summaries[Random.Shared.Next(summaries.Length)]
|
||||
// })
|
||||
// .ToArray();
|
||||
// return forecast;
|
||||
//})
|
||||
//.WithName("GetWeatherForecast")
|
||||
//.WithOpenApi();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user