|
|
|
|
using System.Text.Json;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Extensions.DependencyInjection;
|
|
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using HybirdFrameworkCore.Configuration;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using SqlSugar.IOC;
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
|
|
|
|
builder.Host.ConfigureContainer<ContainerBuilder>(cb =>
|
|
|
|
|
{
|
|
|
|
|
cb.Register(c =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var db = new SqlSugarClient(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>ʹ<EFBFBD><CAB9>ʵ<EFBFBD><CAB5><EFBFBD><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());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
builder.Logging.AddLog4Net("log4net.config");
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
|
|
app.Run();
|