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.
58 lines
1.6 KiB
58 lines
1.6 KiB
using Autofac;
|
|
using Autofac.Extensions.DependencyInjection;
|
|
using HybirdFrameworkCore.Autofac;
|
|
using HybirdFrameworkCore.Configuration;
|
|
using HybirdFrameworkDriver.TcpServer;
|
|
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, // 设置数据库连接字符串
|
|
DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer,
|
|
IsAutoCloseConnection = true,
|
|
InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute
|
|
});
|
|
return db;
|
|
}).As<ISqlSugarClient>().InstancePerLifetimeScope();
|
|
|
|
|
|
|
|
cb.RegisterModule(new AutofacModuleRegister());
|
|
});
|
|
|
|
|
|
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();
|
|
|
|
AppInfo.Container = app.Services.GetAutofacRoot();
|
|
|
|
Server server = AppInfo.Container.Resolve<Server>();
|
|
server.Start(9000);
|
|
|
|
app.Run(); |