xianhc / apevolo-api

.Net 8 、SqlSugar ORM、Vue 2.X、RBAC、前后端分离的开箱则用的企业级中后台权限管理系统
https://www.apevolo.com
Apache License 2.0
809 stars 74 forks source link

\apevolo-api\ApeVolo.Repository\Base\SugarHandler.cs 为啥要创建2个private SqlSugarClient? #3

Closed huster-songtao closed 2 years ago

huster-songtao commented 2 years ago
        public SugarHandler(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
            _dbBase = unitOfWork.GetDbClient();
        }

        internal ISqlSugarClient Db
        {
            get { return _db; }
        }

        private readonly IUnitOfWork _unitOfWork;
        private SqlSugarClient _dbBase;

        private ISqlSugarClient _db => _dbBase;

对于引用类型,两种变量可引用同一对象;因此,对一个变量执行的操作会影响另一个变量所引用的对象。 _db 和_dbBase 保留一个,_unitOfWork可以直接去掉

        public SugarHandler(IUnitOfWork unitOfWork)
        {
            //_unitOfWork = unitOfWork;
            _db = unitOfWork.GetDbClient();
        }

        internal ISqlSugarClient Db
        {
            get { return _db; }
        }

        //private readonly IUnitOfWork _unitOfWork;
        private SqlSugarClient _db;

        //private ISqlSugarClient _db => _dbBase;

btw:警告能不能都消一下?

1>D:\github\apevolo-api\ApeVolo.Common\SnowflakeIdHelper\SnowflakeIdWorker.cs(53,47,53,50): warning CS0628: “SnowflakeIdWorker.WorkerId.set”: 在密封类型中声明了新的保护成员 1>D:\github\apevolo-api\ApeVolo.Common\SnowflakeIdHelper\SnowflakeIdWorker.cs(54,51,54,54): warning CS0628: “SnowflakeIdWorker.DatacenterId.set”: 在密封类型中声明了新的保护成员 1>D:\github\apevolo-api\ApeVolo.Common\Extention\Ext.Byte.cs(163,20,163,45): warning SYSLIB0011: “IFormatter.Deserialize(Stream)”已过时:“BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.” 1>D:\github\apevolo-api\ApeVolo.Common\Caches\Redis\Service\MessageQueue\InitCore.cs(52,65,52,67): warning CS1998: 此异步方法缺少 "await" 运算符,将以同步方式运行。请考虑使用 "await" 运算符等待非阻止的 API 调用,或者使用 "await Task.Run(...)" 在后台线程上执行占用大量 CPU 的工作。 1>D:\github\apevolo-api\ApeVolo.Common\Helper\SaltKeyHelper.cs(18,28,18,52): warning SYSLIB0023: “RNGCryptoServiceProvider”已过时:“RNGCryptoServiceProvider is obsolete. To generate a random number, use one of the RandomNumberGenerator static methods instead.” 1>D:\github\apevolo-api\ApeVolo.Common\Extention\Ext.Object.cs(27,13,27,41): warning SYSLIB0011: “IFormatter.Serialize(Stream, object)”已过时:“BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.” 1>D:\github\apevolo-api\ApeVolo.Common\Extention\Ext.String.cs(186,29,186,54): warning SYSLIB0021: “SHA1CryptoServiceProvider”已过时:“Derived cryptographic types are obsolete. Use the Create method on the base type instead.” 1>D:\github\apevolo-api\ApeVolo.Common\Helper\HttpHelper.cs(160,50,160,75): warning SYSLIB0014: “WebRequest.Create(string)”已过时:“WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.” 1>D:\github\apevolo-api\ApeVolo.Common\Helper\HttpHelper.cs(321,61,321,83): warning SYSLIB0014: “WebRequest.Create(string)”已过时:“WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.” 1>D:\github\apevolo-api\ApeVolo.Common\Caches\Redis\Service\MessageQueue\InitCore.cs(175,69,175,71): warning CS1998: 此异步方法缺少 "await" 运算符,将以同步方式运行。请考虑使用 "await" 运算符等待非阻止的 API 调用,或者使用 "await Task.Run(...)" 在后台线程上执行占用大量 CPU 的工作。 1>D:\github\apevolo-api\ApeVolo.Common\Caches\Redis\Service\MessageQueue\InitCore.cs(96,45,96,47): warning CS1998: 此异步方法缺少 "await" 运算符,将以同步方式运行。请考虑使用 "await" 运算符等待非阻止的 API 调用,或者使用 "await Task.Run(...)" 在后台线程上执行占用大量 CPU 的工作。 1>D:\github\apevolo-api\ApeVolo.Common\Caches\Redis\Service\MessageQueue\ServiceCollectionExtensions.cs(19,77,19,87): warning CS1574: XML 注释中有未能解析的 cref 特性“CapOptions” 1>D:\github\apevolo-api\ApeVolo.Common\Caches\Redis\Service\MessageQueue\ServiceCollectionExtensions.cs(20,36,20,46): warning CS1574: XML 注释中有未能解析的 cref 特性“CapBuilder”

最后2个,我发了一个issue,https://github.com/wmowm/InitQ/issues/8

xianhc commented 2 years ago

@huster-songtao 感谢你的提议,项目是长期持续增加功能并优化的,架构不好的地方会逐步优化