From d4a6b1d7f8ccd1164afb1b3907358c47e1517be6 Mon Sep 17 00:00:00 2001
From: FalconFly <12919280+falconfly@user.noreply.gitee.com>
Date: Mon, 24 Jun 2024 15:22:21 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=97=A5=E5=BF=97?=
=?UTF-8?q?=E4=B8=8D=E6=98=AF=E5=BF=85=E9=A1=BB=E7=9A=84=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DatabaseManager/DbContextBase.cs | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/Falcon.SugarApi/DatabaseManager/DbContextBase.cs b/Falcon.SugarApi/DatabaseManager/DbContextBase.cs
index dd2dc78..2092045 100644
--- a/Falcon.SugarApi/DatabaseManager/DbContextBase.cs
+++ b/Falcon.SugarApi/DatabaseManager/DbContextBase.cs
@@ -12,7 +12,7 @@ namespace Falcon.SugarApi.DatabaseManager
///
/// 保存数据库日志
///
- public ILogger Logger { get; set; }
+ public ILogger? Logger { get; set; }
///
/// 使用链接配置构造数据库链接
@@ -20,7 +20,22 @@ namespace Falcon.SugarApi.DatabaseManager
/// 数据库配置
/// 服务提供器
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);
+ };
}
///