From eb1a86e5b2ad4b96ae36c0ce72f2300b9bdb0d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Wed, 18 Jan 2023 00:34:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=B7=A5=E4=BD=9C=E5=8D=95?= =?UTF-8?q?=E5=85=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Uow/UnitOfWork.cs | 23 ++++++++++++++----- .../YiFrameworkCoreSqlsugarModule.cs | 1 + .../Yi.Framework.Ddd/Yi.Framework.Ddd.csproj | 1 - .../framework/Yi.Framework.Uow/IUnitOfWork.cs | 2 ++ .../Yi.Framework.Uow/Yi.Framework.Uow.csproj | 4 ++++ .../ApplicationSwaggerDoc.xml | 4 ++-- .../Student/StudentService.cs | 5 +++- .../Yi.Framework.Application.csproj | 1 + .../test/Yi.Framework.Web/TimeTest.txt | 1 + 9 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Uow/UnitOfWork.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Uow/UnitOfWork.cs index 3a5545c5..91bad224 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Uow/UnitOfWork.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Uow/UnitOfWork.cs @@ -1,21 +1,24 @@ -using SqlSugar; +using Microsoft.Extensions.DependencyInjection; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Model; +using Yi.Framework.Ddd.Repositories; using Yi.Framework.Uow; namespace Yi.Framework.Core.Sqlsugar.Uow { public class UnitOfWork : IUnitOfWork { - public ISqlSugarClient Db { get; set; } - public ITenant Tenant { get; set; } - public bool IsTran { get; set; } - public bool IsCommit { get; set; } - public bool IsClose { get; set; } + public ISqlSugarClient Db { get; set; } + public ITenant Tenant { get; set; } + public bool IsTran { get; set; } + public bool IsCommit { get; set; } + public bool IsClose { get; set; } public void Dispose() { @@ -44,5 +47,13 @@ namespace Yi.Framework.Core.Sqlsugar.Uow } return IsCommit; } + + public IRepository GetRepository() + { + if (ServiceLocatorModel.Instance is null) + throw new ArgumentNullException("ServiceLocatorModel.Instance"); + //又是你这个骚东西 + return ServiceLocatorModel.Instance.GetRequiredService>(); + } } } diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs index c73bacb8..f8ac584f 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs @@ -25,6 +25,7 @@ namespace Yi.Framework.Core.Sqlsugar services.AddSingleton(); + services.Configure(Appsettings.appConfiguration("DbConnOptions")); services.AddSqlsugarServer(); diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Yi.Framework.Ddd.csproj b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Yi.Framework.Ddd.csproj index af17369b..4d82bdc4 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Yi.Framework.Ddd.csproj +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Yi.Framework.Ddd.csproj @@ -12,7 +12,6 @@ - diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/IUnitOfWork.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/IUnitOfWork.cs index 172b9732..5799a351 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/IUnitOfWork.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/IUnitOfWork.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Ddd.Repositories; namespace Yi.Framework.Uow { @@ -12,6 +13,7 @@ namespace Yi.Framework.Uow bool IsCommit { get; set; } bool IsClose { get; set; } + IRepository GetRepository(); bool Commit(); } } diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/Yi.Framework.Uow.csproj b/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/Yi.Framework.Uow.csproj index 132c02c5..37b50758 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/Yi.Framework.Uow.csproj +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Uow/Yi.Framework.Uow.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/Yi.Framework.Net6/test/Yi.Framework.Application/ApplicationSwaggerDoc.xml b/Yi.Framework.Net6/test/Yi.Framework.Application/ApplicationSwaggerDoc.xml index 01c24fd7..54b66b5e 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Application/ApplicationSwaggerDoc.xml +++ b/Yi.Framework.Net6/test/Yi.Framework.Application/ApplicationSwaggerDoc.xml @@ -9,9 +9,9 @@ 服务实现 - + - 你好世界 + Uow diff --git a/Yi.Framework.Net6/test/Yi.Framework.Application/Student/StudentService.cs b/Yi.Framework.Net6/test/Yi.Framework.Application/Student/StudentService.cs index 9279a54d..7d97e51a 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Application/Student/StudentService.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Application/Student/StudentService.cs @@ -28,13 +28,15 @@ namespace Yi.Framework.Application.Student { private readonly IStudentRepository _studentRepository; private readonly StudentManager _studentManager; - private readonly IUnitOfWorkManager _unitOfWorkManager; + //private readonly IUnitOfWorkManager _unitOfWorkManager; public StudentService(IStudentRepository studentRepository, StudentManager studentManager, IUnitOfWorkManager unitOfWorkManager) { _studentRepository = studentRepository; _studentManager = studentManager; _unitOfWorkManager = unitOfWorkManager; } + + private readonly IUnitOfWorkManager _unitOfWorkManager; /// /// Uow /// @@ -44,6 +46,7 @@ namespace Yi.Framework.Application.Student StudentGetOutputDto res = new(); using (var uow = _unitOfWorkManager.CreateContext()) { + var studentRepository = uow.GetRepository(); res = await base.CreateAsync(new StudentCreateInputVo { Name = $"老杰哥{DateTime.Now.ToString("ffff")}", Number = 2023 }); if (new Random().Next(0, 2) == 0) throw new NotImplementedException(); uow.Commit(); diff --git a/Yi.Framework.Net6/test/Yi.Framework.Application/Yi.Framework.Application.csproj b/Yi.Framework.Net6/test/Yi.Framework.Application/Yi.Framework.Application.csproj index 16e3b0a4..5d913a96 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Application/Yi.Framework.Application.csproj +++ b/Yi.Framework.Net6/test/Yi.Framework.Application/Yi.Framework.Application.csproj @@ -9,6 +9,7 @@ + diff --git a/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt b/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt index 2180c9a2..0c96cabe 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt +++ b/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt @@ -32,3 +32,4 @@ 2023:01:17-22:45:52本次运行启动时间为:1877毫秒 2023:01:17-23:24:07本次运行启动时间为:1836毫秒 2023:01:17-23:29:20本次运行启动时间为:1958毫秒 +2023:01:17-23:45:25本次运行启动时间为:2016毫秒