|
|
using Autofac;
|
|
|
using Autofac.Extensions.DependencyInjection;
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
using HybirdFrameworkCore.AutoTask;
|
|
|
using HybirdFrameworkCore.Configuration;
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
using HybirdFrameworkCore.Redis;
|
|
|
using log4net;
|
|
|
using Service.Car.Server;
|
|
|
using Service.TBox.Server;
|
|
|
using SqlSugar;
|
|
|
using SqlSugar.IOC;
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
var log = LogManager.GetLogger(typeof(Program));
|
|
|
|
|
|
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
|
|
builder.Host.ConfigureContainer<ContainerBuilder>(cb =>
|
|
|
{
|
|
|
cb.Register(c =>
|
|
|
{
|
|
|
var db = new SqlSugarScope(new ConnectionConfig
|
|
|
{
|
|
|
ConfigId = AppSettingsConstVars.ConfigId,
|
|
|
ConnectionString = AppSettingsConstVars.DbSqlConnection, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer,
|
|
|
IsAutoCloseConnection = true,
|
|
|
InitKeyType = InitKeyType.Attribute // <20><><EFBFBD>ʹ<EFBFBD><CAB9>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ InitKeyType.Attribute
|
|
|
});
|
|
|
return db;
|
|
|
}).As<ISqlSugarClient>().InstancePerLifetimeScope();
|
|
|
|
|
|
|
|
|
cb.RegisterModule(new AutofacModuleRegister());
|
|
|
});
|
|
|
//跨域
|
|
|
builder.Services.AddCors(options =>
|
|
|
{
|
|
|
options.AddPolicy
|
|
|
(name: "myCors",
|
|
|
builde =>
|
|
|
{
|
|
|
builde.WithOrigins("*", "*", "*")
|
|
|
.AllowAnyOrigin()
|
|
|
.AllowAnyHeader()
|
|
|
.AllowAnyMethod();
|
|
|
}
|
|
|
);
|
|
|
});
|
|
|
|
|
|
builder.Services.AddSwaggerGen(c =>
|
|
|
{
|
|
|
var basePath = Path.GetDirectoryName(AppContext.BaseDirectory);
|
|
|
//c.IncludeXmlComments(Path.Combine(basePath, Assembly.GetExecutingAssembly().GetName().Name+".xml"), true);
|
|
|
c.IncludeXmlComments(Path.Combine(basePath, "WebStarter.xml"), true);
|
|
|
c.IncludeXmlComments(Path.Combine(basePath, "Entity.xml"), true);
|
|
|
c.IncludeXmlComments(Path.Combine(basePath, "HybirdFrameworkCore.xml"), true);
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
builder.Services.AddControllers().AddJsonOptions(configure =>
|
|
|
{
|
|
|
configure.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
|
|
|
});
|
|
|
//redis
|
|
|
var redisConnectionString = AppSettingsHelper.GetContent("Redis", "Connection");
|
|
|
var instanceName = AppSettingsHelper.GetContent("Redis", "InstanceName");//默认数据库
|
|
|
var defaultDb = int.Parse(AppSettingsHelper.GetContent("Redis", "DefaultDB") ?? "0");
|
|
|
if (redisConnectionString != null && instanceName != null)
|
|
|
builder.Services.AddSingleton(new RedisHelper(redisConnectionString, instanceName, defaultDb));
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
builder.Logging.AddLog4Net("log4net.config");
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
// Configure the HTTP request pipeline.
|
|
|
app.UseSwagger();
|
|
|
app.UseSwaggerUI();
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
app.UseCors("myCors");
|
|
|
app.MapControllers();
|
|
|
|
|
|
var list = AppSettingsHelper.GetContent("Kestrel", "Endpoints", "http", "Url");
|
|
|
foreach (var s in list.Split(";"))
|
|
|
{
|
|
|
log.Info($"use url={s}");
|
|
|
app.Urls.Add(s);
|
|
|
}
|
|
|
|
|
|
AppInfo.Container = app.Services.GetAutofacRoot();
|
|
|
|
|
|
|
|
|
|
|
|
string? tboxType = AppSettingsHelper.GetContent("TBox", "Type");
|
|
|
if ("ygmd" == tboxType)
|
|
|
{
|
|
|
var tBoxListen = builder.Configuration.GetSection("TBoxListen");
|
|
|
TBoxServerMgr.InitTBoxServer(int.Parse(tBoxListen.GetSection("Port").Value ?? "9999"));
|
|
|
}
|
|
|
if ("jx" == tboxType)
|
|
|
{
|
|
|
var listen = builder.Configuration.GetSection("Listen");
|
|
|
CarServerMgr.InitServer(int.Parse(listen.GetSection("Port").Value ?? "5588"));
|
|
|
}
|
|
|
|
|
|
|
|
|
TaskInit.Init();
|
|
|
|
|
|
app.Run();
|