.NET7 IOC注册SqlSugar
// 读取appsetting.json配置文件
IConfiguration _config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, reloadOnChange: true)
.Build();
// 注册sqlsugar
builder.Services.AddTransient<ISqlSugarClient>(p =>
{
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.MySql,
ConnectionString = _config["db_master"],
IsAutoCloseConnection = true
});
return db;
});