From 03702477d6e8dc5b3d4fe80076b936c127648a07 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Sun, 29 Sep 2024 13:57:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=91=E5=B8=83=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessFilter/_Config/_AppSettings.cs | 2 +- .../NeedVerify/AddSubjectTriggerConsumer.cs | 11 ++++++++- .../Service/Common/DTO/PublishLogViewModel.cs | 2 +- IRaCIS.Core.Application/TestService.cs | 24 +++++++++++++++++++ .../AddSubjectTriggerCommand.cs | 1 + 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs b/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs index 76af3c7a9..885c65dd1 100644 --- a/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs +++ b/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs @@ -60,7 +60,7 @@ public class SystemEmailSendConfig public string CompanyShortNameCN { get; set; } = string.Empty; - public string IsEnv_US { get; set; } + public bool IsEnv_US { get; set; } } public class SystemEmailSendConfigView diff --git a/IRaCIS.Core.Application/MassTransit/Consumer/NeedVerify/AddSubjectTriggerConsumer.cs b/IRaCIS.Core.Application/MassTransit/Consumer/NeedVerify/AddSubjectTriggerConsumer.cs index 3a2e67594..67779cc06 100644 --- a/IRaCIS.Core.Application/MassTransit/Consumer/NeedVerify/AddSubjectTriggerConsumer.cs +++ b/IRaCIS.Core.Application/MassTransit/Consumer/NeedVerify/AddSubjectTriggerConsumer.cs @@ -3,6 +3,7 @@ using AutoMapper; using IRaCIS.Core.Domain; using MassTransit; +using Microsoft.EntityFrameworkCore; namespace IRaCIS.Core.Application.MassTransit.Consumer; @@ -22,7 +23,15 @@ public class AddSubjectTriggerConsumer(IRepository _subjectVisitRe { public async Task Consume(ConsumeContext context) { - var addSubjectEvent= context.Message; + var addSubjectEvent = context.Message; + + + { + Console.WriteLine(_visitStageRepository._dbContext.GetHashCode()); + + Console.WriteLine("两个 DbContext 不是同一个实例"); + } + //添加受试者的时候,获取访视计划列表,添加到受试者访视表。 var visitPlanList = await _visitStageRepository.Where(t => t.TrialId == addSubjectEvent.TrialId && t.IsConfirmed).ToListAsync(); diff --git a/IRaCIS.Core.Application/Service/Common/DTO/PublishLogViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/PublishLogViewModel.cs index b8282daaf..80f3f783a 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/PublishLogViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/PublishLogViewModel.cs @@ -14,7 +14,7 @@ namespace IRaCIS.Core.Application.ViewModel public Guid UpdateUserId { get; set; } public DateTime UpdateTime { get; set; } - public string IsEnv_US { get; set; } + public bool IsEnv_US { get; set; } } ///PublishLogQuery 列表查询参数模型 diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index f1fd4242b..244937a70 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -6,6 +6,7 @@ using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Domain; using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure.Encryption; using IRaCIS.Core.Infrastructure.NewtonsoftJson; @@ -18,8 +19,11 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MiniExcelLibs; +using NPOI.SS.Formula.Functions; using NPOI.XWPF.UserModel; +using System.Runtime.InteropServices; using System.Text; +using Tea; namespace IRaCIS.Core.Application.Service @@ -121,12 +125,32 @@ namespace IRaCIS.Core.Application.Service } + //My project is a monolithic project,And the efcore context repository is scoped registered. public async Task TestMasstransitMeditor([FromServices] IMediator _mediator, [FromServices] IRepository _testLengthRepository) { + + var dbContext = _testLengthRepository._dbContext; + + + var dbContext2 = _trialRepository._dbContext; + + if (ReferenceEquals(dbContext, dbContext2)) + { + Console.WriteLine("两个 DbContext 是同一个实例"); + + Console.WriteLine(dbContext.GetHashCode()); + Console.WriteLine(dbContext2.GetHashCode()); + } + + + + // add 1 recored await _testLengthRepository.AddAsync(new TestLength() { Name = "xxxx" }); + // The consumer method will inject the repository and add 3 pieces of data, but the savechanges method of the repository will not be called await _mediator.Send(new AddSubjectTriggerCommand { SubjectId = Guid.Empty }); + // this will save 1 record not 4 record ,Why is the dbcontext different? Can it be in the same transaction? await _testLengthRepository.SaveChangesAsync(); return ResponseOutput.Ok(); diff --git a/IRaCIS.Core.Domain/_DomainCommand/AddSubjectTriggerCommand.cs b/IRaCIS.Core.Domain/_DomainCommand/AddSubjectTriggerCommand.cs index d2b7de732..6e4a2cf73 100644 --- a/IRaCIS.Core.Domain/_DomainCommand/AddSubjectTriggerCommand.cs +++ b/IRaCIS.Core.Domain/_DomainCommand/AddSubjectTriggerCommand.cs @@ -12,4 +12,5 @@ public class AddSubjectTriggerCommand : DomainCommand public Guid TrialId { get; set; } public Guid TrialSiteId { get; set; } + }