.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;
});

posted @ 2023-09-13 15:15  Ratooner  阅读(102)  评论(0编辑  收藏  举报