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

68 lines
2.1 KiB

8 months ago
using Autofac;
using Autofac.Extensions.DependencyInjection;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
7 months ago
using HybirdFrameworkCore.Redis;
7 months ago
using HybirdFrameworkDriver.TcpServer;
8 months ago
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,
7 months ago
ConnectionString = AppSettingsConstVars.DbSqlConnection, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
8 months ago
DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer,
IsAutoCloseConnection = true,
7 months ago
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
8 months ago
});
return db;
}).As<ISqlSugarClient>().InstancePerLifetimeScope();
7 months ago
8 months ago
8 months ago
cb.RegisterModule(new AutofacModuleRegister());
});
7 months ago
//redis
var section = builder.Configuration.GetSection("Redis");
//连接字符串
string? redisConnectionString = section.GetSection("Connection").Value;
//实例名称
string? instanceName = section.GetSection("InstanceName").Value;
//默认数据库
int _defaultDB = int.Parse(section.GetSection("DefaultDB").Value ?? "0");
if (redisConnectionString != null && instanceName != null)
builder.Services.AddSingleton(new RedisHelper(redisConnectionString, instanceName, _defaultDB));
8 months ago
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();
8 months ago
8 months ago
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapControllers();
8 months ago
AppInfo.Container = app.Services.GetAutofacRoot();
app.Run();