From 41c41878e1d98bbb42bfb07d1fd167f54d223e4e Mon Sep 17 00:00:00 2001
From: falcon <9504402@qq.com>
Date: Tue, 22 Mar 2022 15:30:20 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E4=BB=8E=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=E4=B8=AD=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96ILogger?=
=?UTF-8?q?=E5=92=8CSugDbContext=E7=9A=84=E6=97=B6=E5=80=99=E6=8E=92?=
=?UTF-8?q?=E9=99=A4=E5=BC=82=E5=B8=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs b/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs
index 11bd30a..93452ff 100644
--- a/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs
+++ b/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs
@@ -39,11 +39,14 @@ namespace Falcon.SugarApi.ApiDefinistions
return $":{con}:{ac}";
}
}
-
+ ///
+ /// 构造控制器基类
+ ///
+ ///
protected ApiControllerBase(IServiceProvider service) {
this.Services = service;
- this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger;
- this.SugarDb = service.GetService();
+ this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger ?? throw new NullReferenceException("ILogger");
+ this.SugarDb = service.GetService() ?? throw new NullReferenceException("SugarDbContext");
}
///
@@ -77,7 +80,7 @@ namespace Falcon.SugarApi.ApiDefinistions
/// 对象的类型
/// json字符串
/// 对象实例
- protected T JsonDeserialize(string json) {
+ protected T? JsonDeserialize(string json) where T: class {
return JsonSerializer.Deserialize(json);
}