You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Microsoft.OpenApi.Models;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddControllers();
//// 注册 SqlSugarClient
builder.Services.AddScoped<SqlSugar.ISqlSugarClient>(provider =>
{
var connectionConfig = new SqlSugar.ConnectionConfig
{
ConnectionString = builder.Configuration.GetConnectionString("YourConnectionStringName"), // 这里替换为你的连接字符串
DbType = SqlSugar.DbType.MySql, // 数据库类型
IsAutoCloseConnection = true, // 自动释放数据务,如果存在事务,在事务结束后释放
InitKeyType = SqlSugar.InitKeyType.Attribute // 从实体特性中读取主键自增列信息
};
var sqlSugarClient = new SqlSugar.SqlSugarClient(connectionConfig);
return sqlSugarClient;
});
// 注册 MediatR 和请求处理器
var assembly = AppDomain.CurrentDomain.Load("Ds.WMS.Finance.MediatR");
builder.Services.AddMediatR(c =>
{
c.RegisterServicesFromAssembly(assembly);
});
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
//builder.Services.AddMediatR(Assembly.GetExecutingAssembly());
var app = builder.Build();
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
// app.UseSwagger();
// app.UseSwaggerUI();
//}
// 启用中间件服务生成 Swagger 作为 JSON 终结点
app.UseSwagger();
// 启用中间件服务对 swagger-ui指定 Swagger JSON 终结点
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.Run();