数据库日志不是必须的。

This commit is contained in:
FalconFly 2024-06-24 15:22:21 +08:00
parent ecb879b571
commit d4a6b1d7f8

View File

@ -12,7 +12,7 @@ namespace Falcon.SugarApi.DatabaseManager
/// <summary> /// <summary>
/// 保存数据库日志 /// 保存数据库日志
/// </summary> /// </summary>
public ILogger Logger { get; set; } public ILogger? Logger { get; set; }
/// <summary> /// <summary>
/// 使用链接配置构造数据库链接 /// 使用链接配置构造数据库链接
@ -20,7 +20,22 @@ namespace Falcon.SugarApi.DatabaseManager
/// <param name="config">数据库配置</param> /// <param name="config">数据库配置</param>
/// <param name="service">服务提供器</param> /// <param name="service">服务提供器</param>
public DbContextBase(ConnectionConfig config,IServiceProvider service) : base(config) { public DbContextBase(ConnectionConfig config,IServiceProvider service) : base(config) {
this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger ?? throw new NullReferenceException("ILogger"); this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger;
ConfigureExternalServices(this.CurrentConnectionConfig);
}
private static void ConfigureExternalServices(ConnectionConfig config) {
config.ConfigureExternalServices ??= new ConfigureExternalServices();
var ces = config.ConfigureExternalServices;
ces.EntityNameService = (t,e) => {
new TableNameTableService().SetupTable(t,e);
};
ces.EntityService = (p,c) => {
new SetupKeyColumnServices().SetupColumn(p,c);
new SetupLengthColumnServices().SetupColumn(p,c);
new SetupNullableColumnServices().SetupColumn(p,c);
new JsonTypeColumnServices().SetupColumn(p,c);
};
} }
/// <summary> /// <summary>