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