
using System.Text;
using Autofac.Extensions.DependencyInjection;
using Autofac;
using WmsMobileServe.AppRunning;
using WmsMobileServe.Utils;

Console.Title = "WMS后台服务";
Console.OutputEncoding = Encoding.UTF8;
ConsoleLog.DisbleQuickEditMode();

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers().AddJsonOptions(options =>
{
    options.JsonSerializerOptions.PropertyNamingPolicy = null; // 修改返回配置，返回原实体类数据
});
builder.Services.AddHostedService<HostService>();
// 添加跨域，允许任何人访问
builder.Services.AddCors(options =>
{
    options.AddPolicy("any", policyBuilder =>
    {
        policyBuilder.WithOrigins("*").AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
    });
});
builder.WebHost.UseUrls("http://*:19990");
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); // 使用 autoFac 替换注入容器
builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
{
    builder.RegisterModule<AutofacModule>();
});

var app = builder.Build();
app.UseCors("any");
app.UseAuthorization();
app.MapControllers();
app.Run();
