Skip to content

Commit ecf682a

Browse files
zhenlei520blazor-component
zhenlei520
authored andcommitted
fix: Fix the problem of failing to get context after enabling soft delete
1 parent c9ba05f commit ecf682a

File tree

44 files changed

+143
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+143
-116
lines changed

MASA.Contrib.sln

+23-23
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DDD", "DDD", "{21180442-A6A
4040
EndProject
4141
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data", "Data", "{E33ADF54-4D35-49B7-BDA6-412587CA39FF}"
4242
EndProject
43-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contrib.Data.Uow.EF", "src\Data\MASA.Contrib.Data.Uow.EF\MASA.Contrib.Data.Uow.EF.csproj", "{626631CD-4FD5-424E-A678-27653F38CA3E}"
44-
EndProject
45-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contrib.Data.Uow.EF.Tests", "test\MASA.Contrib.Data.Uow.EF.Tests\MASA.Contrib.Data.Uow.EF.Tests.csproj", "{63BB9F58-316E-4F20-8F45-B45D28FC2476}"
46-
EndProject
4743
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contrib.Dispatcher.Events", "src\Dispatcher\MASA.Contrib.Dispatcher.Events\MASA.Contrib.Dispatcher.Events.csproj", "{1B44F2E7-28F5-4E88-B8A8-3F336800FD5C}"
4844
EndProject
4945
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contrib.Dispatcher.Events.BenchmarkDotnetTest", "test\MASA.Contrib.Dispatcher.Events.BenchmarkDotnetTest\MASA.Contrib.Dispatcher.Events.BenchmarkDotnetTest.csproj", "{0FF80D58-98D2-43E9-8EAF-7F47C31CB0B6}"
@@ -92,7 +88,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contribs.DDD.Domain.En
9288
EndProject
9389
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MASA.Contrib.DDD.Domain.Repository.EF", "MASA.Contrib.DDD.Domain.Repository.EF", "{880E8263-AECC-4793-BD28-7CD03650D124}"
9490
EndProject
95-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MASA.Contrib.DDD.Domain.Repository.EF.CustomRepository", "test\MASA.Contrib.DDD.Domain.Repository.EF.CustomRepository\MASA.Contrib.DDD.Domain.Repository.EF.CustomRepository.csproj", "{7A1493EC-196F-4389-A966-02E526453578}"
91+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contrib.DDD.Domain.Repository.EF.CustomRepository", "test\MASA.Contrib.DDD.Domain.Repository.EF.CustomRepository\MASA.Contrib.DDD.Domain.Repository.EF.CustomRepository.csproj", "{7A1493EC-196F-4389-A966-02E526453578}"
92+
EndProject
93+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contrib.Data.UoW.EF", "src\Data\MASA.Contrib.Data.UoW.EF\MASA.Contrib.Data.UoW.EF.csproj", "{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}"
94+
EndProject
95+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.Contrib.Data.UoW.EF.Tests", "test\MASA.Contrib.Data.UoW.EF.Tests\MASA.Contrib.Data.UoW.EF.Tests.csproj", "{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}"
9696
EndProject
9797
Global
9898
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -110,22 +110,6 @@ Global
110110
{ED301FA5-4E70-460B-A0D4-1D79D135769F}.Release|Any CPU.Build.0 = Release|Any CPU
111111
{ED301FA5-4E70-460B-A0D4-1D79D135769F}.Release|x64.ActiveCfg = Release|Any CPU
112112
{ED301FA5-4E70-460B-A0D4-1D79D135769F}.Release|x64.Build.0 = Release|Any CPU
113-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
114-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
115-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Debug|x64.ActiveCfg = Debug|Any CPU
116-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Debug|x64.Build.0 = Debug|Any CPU
117-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
118-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Release|Any CPU.Build.0 = Release|Any CPU
119-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Release|x64.ActiveCfg = Release|Any CPU
120-
{626631CD-4FD5-424E-A678-27653F38CA3E}.Release|x64.Build.0 = Release|Any CPU
121-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
122-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Debug|Any CPU.Build.0 = Debug|Any CPU
123-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Debug|x64.ActiveCfg = Debug|Any CPU
124-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Debug|x64.Build.0 = Debug|Any CPU
125-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Release|Any CPU.ActiveCfg = Release|Any CPU
126-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Release|Any CPU.Build.0 = Release|Any CPU
127-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Release|x64.ActiveCfg = Release|Any CPU
128-
{63BB9F58-316E-4F20-8F45-B45D28FC2476}.Release|x64.Build.0 = Release|Any CPU
129113
{1B44F2E7-28F5-4E88-B8A8-3F336800FD5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
130114
{1B44F2E7-28F5-4E88-B8A8-3F336800FD5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
131115
{1B44F2E7-28F5-4E88-B8A8-3F336800FD5C}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -310,6 +294,22 @@ Global
310294
{7A1493EC-196F-4389-A966-02E526453578}.Release|Any CPU.Build.0 = Release|Any CPU
311295
{7A1493EC-196F-4389-A966-02E526453578}.Release|x64.ActiveCfg = Release|Any CPU
312296
{7A1493EC-196F-4389-A966-02E526453578}.Release|x64.Build.0 = Release|Any CPU
297+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
298+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
299+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Debug|x64.ActiveCfg = Debug|Any CPU
300+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Debug|x64.Build.0 = Debug|Any CPU
301+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
302+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Release|Any CPU.Build.0 = Release|Any CPU
303+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Release|x64.ActiveCfg = Release|Any CPU
304+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F}.Release|x64.Build.0 = Release|Any CPU
305+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
306+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
307+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Debug|x64.ActiveCfg = Debug|Any CPU
308+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Debug|x64.Build.0 = Debug|Any CPU
309+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
310+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Release|Any CPU.Build.0 = Release|Any CPU
311+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Release|x64.ActiveCfg = Release|Any CPU
312+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7}.Release|x64.Build.0 = Release|Any CPU
313313
EndGlobalSection
314314
GlobalSection(SolutionProperties) = preSolution
315315
HideSolutionNode = FALSE
@@ -329,8 +329,6 @@ Global
329329
{ED301FA5-4E70-460B-A0D4-1D79D135769F} = {593A3114-D1E0-47ED-BC37-58E08886175B}
330330
{21180442-A6A5-4239-A2AD-33FF5BB80E72} = {42DF7AAC-362C-48F4-B76A-BDEEEFF17CC9}
331331
{E33ADF54-4D35-49B7-BDA6-412587CA39FF} = {42DF7AAC-362C-48F4-B76A-BDEEEFF17CC9}
332-
{626631CD-4FD5-424E-A678-27653F38CA3E} = {E33ADF54-4D35-49B7-BDA6-412587CA39FF}
333-
{63BB9F58-316E-4F20-8F45-B45D28FC2476} = {38E6C400-90C0-493E-9266-C1602E229F1B}
334332
{1B44F2E7-28F5-4E88-B8A8-3F336800FD5C} = {FBD326D3-E59C-433E-A88E-14E179E3093D}
335333
{0FF80D58-98D2-43E9-8EAF-7F47C31CB0B6} = {2BE750A5-8AC7-457C-9BB2-6E3D5E2D23B8}
336334
{D55A7D3B-9C24-4029-BC03-41B28AD11DB6} = {2BE750A5-8AC7-457C-9BB2-6E3D5E2D23B8}
@@ -356,6 +354,8 @@ Global
356354
{647A9FC3-4C21-4CD1-AD6A-FADFEB976E32} = {13EDB361-AF88-4F89-B4AB-46622BCCBC37}
357355
{880E8263-AECC-4793-BD28-7CD03650D124} = {38E6C400-90C0-493E-9266-C1602E229F1B}
358356
{7A1493EC-196F-4389-A966-02E526453578} = {880E8263-AECC-4793-BD28-7CD03650D124}
357+
{1265AE3C-B5FD-4339-8A7D-BC598E6E1C9F} = {E33ADF54-4D35-49B7-BDA6-412587CA39FF}
358+
{1B16DD58-0847-45A7-AF93-53EBFBEDAAE7} = {38E6C400-90C0-493E-9266-C1602E229F1B}
359359
EndGlobalSection
360360
GlobalSection(ExtensibilityGlobals) = postSolution
361361
SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MASA.Contrib
1212
│ ├── nuget.config
1313
├── src
1414
│ ├── Data
15-
│ │ ├── MASA.Contrib.Data.Uow.EF Unit of work
15+
│ │ ├── MASA.Contrib.Data.UoW.EF Unit of work
1616
│ │ └── MASA.Contribs.Data.Contracts.EF Protocol EF version
1717
│ ├── DDD
1818
│ │ ├── MASA.Contribs.DDD.Domain In-process and cross-process support
@@ -36,7 +36,7 @@ MASA.Contrib
3636
│ │ ├── MASA.Contrib.Dispatcher.Events.OnlyCancelHandler.Tests
3737
│ │ ├── MASA.Contrib.Dispatcher.Events.CheckMethodsType.Tests
3838
│ │ ├── MASA.Contrib.Dispatcher.Events.Tests
39-
│ ├── MASA.Contrib.Data.Uow.EF.Tests
39+
│ ├── MASA.Contrib.Data.UoW.EF.Tests
4040
│ ├── MASA.Contrib.Dispatcher.IntegrationEvents.EventLogs.EF.Tests
4141
│ ├── MASA.Contribs.DDD.Domain.Tests
4242
│ ├── MASA.Contribs.DDD.Domain.Repository.EF.Tests

README.zh-CN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# MASA.Contrib
44

5-
MASA.Contrib是基于[MASA.BuildingBlocks](https://github.com/masastack/MASA.BuildingBlocks)提供开放, 社区驱动的可重用组件,用于构建网格应用程序。这些组件将被[MASA Stack](https://github.com/masastack)[MASA Labs](https://github.com/masalabs)等项目使用。
5+
MASA.Contrib是基于[MASA.BuildingBlocks](https://github.com/masastack/MASA.BuildingBlocks)提供开放, 社区驱动的可重用组件,用于构建网格应用程序。这些组件将被[MASA Stack](https://github.com/masastack)[MASA Labs](https://github.com/masalabs)等项目使用。
66

77
## 结构
88

@@ -12,7 +12,7 @@ MASA.Contrib
1212
│ ├── nuget.config
1313
├── src
1414
│ ├── Data
15-
│ │ ├── MASA.Contrib.Data.Uow.EF 工作单元
15+
│ │ ├── MASA.Contrib.Data.UoW.EF 工作单元
1616
│ │ └── MASA.Contribs.Data.Contracts.EF 规约EF
1717
│ ├── DDD
1818
│ │ ├── MASA.Contribs.DDD.Domain 进程内、跨进程都支持
@@ -36,7 +36,7 @@ MASA.Contrib
3636
│ │ ├── MASA.Contrib.Dispatcher.Events.OnlyCancelHandler.Tests
3737
│ │ ├── MASA.Contrib.Dispatcher.Events.CheckMethodsType.Tests
3838
│ │ ├── MASA.Contrib.Dispatcher.Events.Tests
39-
│ ├── MASA.Contrib.Data.Uow.EF.Tests
39+
│ ├── MASA.Contrib.Data.UoW.EF.Tests
4040
│ ├── MASA.Contrib.Dispatcher.IntegrationEvents.EventLogs.EF.Tests
4141
│ ├── MASA.Contribs.DDD.Domain.Tests
4242
│ ├── MASA.Contribs.DDD.Domain.Repository.EF.Tests

src/DDD/MASA.Contrib.DDD.Domain.Repository.EF/MASA.Contrib.DDD.Domain.Repository.EF.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MASA.BuildingBlocks.DDD.Domain" Version="0.0.7159" />
10+
<PackageReference Include="MASA.BuildingBlocks.DDD.Domain" Version="0.0.7403" />
1111
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-rc.1.21452.10" />
1212
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0-rc.1.21452.10" />
1313
</ItemGroup>

src/DDD/MASA.Contrib.DDD.Domain.Repository.EF/_Imports.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
global using MASA.BuildingBlocks.Data.Uow;
1+
global using MASA.BuildingBlocks.Data.UoW;
22
global using MASA.BuildingBlocks.DDD.Domain.Entities;
33
global using MASA.BuildingBlocks.DDD.Domain.Repositories;
44
global using MASA.BuildingBlocks.Dispatcher.Events;

src/DDD/MASA.Contrib.DDD.Domain/DomainEventBus.cs

+5
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ public async Task PublishQueueAsync()
4747
}
4848
}
4949

50+
public async Task CommitAsync(CancellationToken cancellationToken = default)
51+
{
52+
await _unitOfWork.CommitAsync(cancellationToken);
53+
}
54+
5055
public IEnumerable<Type> GetAllEventTypes() => _options.AllEventTypes.Concat(_eventBus.GetAllEventTypes()).Distinct();
5156
}

src/DDD/MASA.Contrib.DDD.Domain/MASA.Contrib.DDD.Domain.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MASA.BuildingBlocks.DDD.Domain" Version="0.0.7159" />
10+
<PackageReference Include="MASA.BuildingBlocks.DDD.Domain" Version="0.0.7403" />
1111
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0-rc.1.21451.13" />
1212
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0-rc.1.21451.13" />
1313
</ItemGroup>

src/DDD/MASA.Contrib.DDD.Domain/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Install-Package MASA.Contrib.Dispatcher.Events
1212

1313
Install-Package MASA.Contrib.Dispatcher.IntegrationEvents.Dapr
1414
Install-Package MASA.Contrib.Dispatcher.IntegrationEvents.EventLogs.EF
15-
Install-Package MASA.Contrib.Data.Uow.EF
15+
Install-Package MASA.Contrib.Data.UoW.EF
1616
```
1717

1818
1. Add DomainEventBus
@@ -22,7 +22,7 @@ builder.Services
2222
.AddDomainEventBus(options =>
2323
{
2424
options.UseEventBus()//Use in-process events
25-
.UseUow<CustomDbContext>(dbOptions => dbOptions.UseSqlServer("server=localhost;uid=sa;pwd=P@ssw0rd;database=idientity"))
25+
.UseUoW<CustomDbContext>(dbOptions => dbOptions.UseSqlServer("server=localhost;uid=sa;pwd=P@ssw0rd;database=idientity"))
2626
.UseDaprEventBus<IntegrationEventLogService>()///Use cross-process events
2727
.UseEventLog<PaymentDbContext>()
2828
.UseRepository<CustomDbContext>();//Use the EF version of Repository to achieve

src/DDD/MASA.Contrib.DDD.Domain/README.zh-CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Install-Package MASA.Contrib.Dispatcher.Events
1212

1313
Install-Package MASA.Contrib.Dispatcher.IntegrationEvents.Dapr
1414
Install-Package MASA.Contrib.Dispatcher.IntegrationEvents.EventLogs.EF
15-
Install-Package MASA.Contrib.Data.Uow.EF
15+
Install-Package MASA.Contrib.Data.UoW.EF
1616
```
1717

1818
1. 添加DomainEventBus
@@ -22,7 +22,7 @@ builder.Services
2222
.AddDomainEventBus(options =>
2323
{
2424
options.UseEventBus()//使用进程内事件
25-
.UseUow<CustomDbContext>(dbOptions => dbOptions.UseSqlServer("server=localhost;uid=sa;pwd=P@ssw0rd;database=idientity"))
25+
.UseUoW<CustomDbContext>(dbOptions => dbOptions.UseSqlServer("server=localhost;uid=sa;pwd=P@ssw0rd;database=idientity"))
2626
.UseDaprEventBus<IntegrationEventLogService>()///使用跨进程事件
2727
.UseEventLog<PaymentDbContext>()
2828
.UseRepository<CustomDbContext>();//使用Repository的EF版实现

src/DDD/MASA.Contrib.DDD.Domain/ServiceCollectionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IServiceCollection AddDomainEventBus(
2626

2727
if (services.All(service => service.ServiceType != typeof(IUnitOfWork)))
2828
{
29-
throw new Exception("Please add Uow first.");
29+
throw new Exception("Please add UoW first.");
3030
}
3131

3232
if (services.All(service => service.ServiceType != typeof(IIntegrationEventBus)))

src/DDD/MASA.Contrib.DDD.Domain/_Imports.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
global using MASA.BuildingBlocks.Data.Uow;
1+
global using MASA.BuildingBlocks.Data.UoW;
22
global using MASA.BuildingBlocks.DDD.Domain.Entities;
33
global using MASA.BuildingBlocks.DDD.Domain.Events;
44
global using MASA.BuildingBlocks.DDD.Domain.Repositories;

src/Data/MASA.Contrib.Data.Contracts.EF/MASA.Contrib.Data.Contracts.EF.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MASA.BuildingBlocks.Data.Contracts" Version="0.0.7159" />
11-
<PackageReference Include="MASA.BuildingBlocks.Data.Uow" Version="0.0.7159" />
12-
<PackageReference Include="MASA.Utils.Data.EntityFrameworkCore" Version="0.0.7145" />
10+
<PackageReference Include="MASA.BuildingBlocks.Data.Contracts" Version="0.0.7403" />
11+
<PackageReference Include="MASA.BuildingBlocks.Data.UoW" Version="0.0.7403" />
12+
<PackageReference Include="MASA.Utils.Data.EntityFrameworkCore" Version="0.0.7315" />
1313
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-rc.1.21452.10" />
1414
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0-rc.1.21452.10" />
1515
</ItemGroup>

src/Data/MASA.Contrib.Data.Contracts.EF/SoftDelete/TransactionSaveChangesFilter.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ namespace MASA.Contrib.Data.Contracts.EF.SoftDelete
22
{
33
public class TransactionSaveChangesFilter : ISaveChangesFilter
44
{
5-
private readonly IUnitOfWork _unitOfWork;
5+
private readonly IServiceProvider _serviceProvider;
66

7-
public TransactionSaveChangesFilter(IUnitOfWork unitOfWork) => _unitOfWork = unitOfWork;
7+
public TransactionSaveChangesFilter(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
88

99
public void OnExecuting(ChangeTracker changeTracker)
1010
{
1111
changeTracker.DetectChanges();
12-
if (changeTracker.Entries().Any(e => e.State == EntityState.Added || e.State == EntityState.Modified || e.State == EntityState.Deleted) && !_unitOfWork.TransactionHasBegun)
12+
var unitOfWork = _serviceProvider.GetRequiredService<IUnitOfWork>();
13+
if (changeTracker.Entries().Any(e => e.State == EntityState.Added || e.State == EntityState.Modified || e.State == EntityState.Deleted) && !unitOfWork.TransactionHasBegun)
1314
{
14-
var transaction = _unitOfWork.Transaction; // Open the transaction
15+
var transaction = unitOfWork.Transaction; // Open the transaction
1516
}
1617
}
1718
}

src/Data/MASA.Contrib.Data.Contracts.EF/_Imports.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
global using MASA.BuildingBlocks.Data.Contracts;
2-
global using MASA.BuildingBlocks.Data.Uow;
2+
global using MASA.BuildingBlocks.Data.UoW;
33
global using MASA.Contrib.Data.Contracts.EF.SoftDelete;
44
global using MASA.Utils.Data.EntityFrameworkCore;
55
global using Microsoft.EntityFrameworkCore;

src/Data/MASA.Contrib.Data.Uow.EF/DispatcherOptionsExtensions.cs src/Data/MASA.Contrib.Data.UoW.EF/DispatcherOptionsExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MASA.Contrib.Data.Uow.EF;
1+
namespace MASA.Contrib.Data.UoW.EF;
22

33
public static class DispatcherOptionsExtensions
44
{
@@ -12,8 +12,8 @@ public static IDispatcherOptions UseUoW<TDbContext>(
1212
throw new ArgumentNullException(nameof(options.Services));
1313
}
1414

15-
if (options.Services.Any(service => service.ImplementationType == typeof(UowProvider))) return options;
16-
options.Services.AddSingleton<UowProvider>();
15+
if (options.Services.Any(service => service.ImplementationType == typeof(UoWProvider))) return options;
16+
options.Services.AddSingleton<UoWProvider>();
1717

1818
options.Services.AddLogging();
1919
options.Services.AddScoped<IUnitOfWork, UnitOfWork<TDbContext>>();
@@ -27,7 +27,7 @@ public static IDispatcherOptions UseUoW<TDbContext>(
2727
return options;
2828
}
2929

30-
private class UowProvider
30+
private class UoWProvider
3131
{
3232

3333
}

src/Data/MASA.Contrib.Data.Uow.EF/MASA.Contrib.Data.Uow.EF.csproj src/Data/MASA.Contrib.Data.UoW.EF/MASA.Contrib.Data.UoW.EF.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MASA.BuildingBlocks.Data.Uow" Version="0.0.7159" />
11-
<PackageReference Include="MASA.BuildingBlocks.Dispatcher.Events" Version="0.0.7159" />
12-
<PackageReference Include="MASA.Utils.Data.EntityFrameworkCore" Version="0.0.7145" />
10+
<PackageReference Include="MASA.BuildingBlocks.Data.UoW" Version="0.0.7403" />
11+
<PackageReference Include="MASA.BuildingBlocks.Dispatcher.Events" Version="0.0.7403" />
12+
<PackageReference Include="MASA.Utils.Data.EntityFrameworkCore" Version="0.0.7315" />
1313
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-rc.1.21452.10" />
1414
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0-rc.1.21452.10" />
1515
</ItemGroup>
16-
16+
1717
</Project>

src/Data/MASA.Contrib.Data.Uow.EF/Transaction.cs src/Data/MASA.Contrib.Data.UoW.EF/Transaction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text.Json.Serialization;
22

3-
namespace MASA.Contrib.Data.Uow.EF;
3+
namespace MASA.Contrib.Data.UoW.EF;
44

55
public class Transaction : ITransaction
66
{

src/Data/MASA.Contrib.Data.Uow.EF/UnitOfWork.cs src/Data/MASA.Contrib.Data.UoW.EF/UnitOfWork.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MASA.Contrib.Data.Uow.EF;
1+
namespace MASA.Contrib.Data.UoW.EF;
22

33
public class UnitOfWork<TDbContext> : IUnitOfWork
44
where TDbContext : MasaDbContext
@@ -38,7 +38,6 @@ public async Task CommitAsync(CancellationToken cancellationToken = default)
3838
{
3939
if (!TransactionHasBegun)
4040
{
41-
await SaveChangesAsync();
4241
return;
4342
}
4443

src/Data/MASA.Contrib.Data.Uow.EF/_Imports.cs src/Data/MASA.Contrib.Data.UoW.EF/_Imports.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
global using MASA.BuildingBlocks.Data.Uow;
1+
global using MASA.BuildingBlocks.Data.UoW;
22
global using MASA.BuildingBlocks.Dispatcher.Events;
33
global using MASA.Utils.Data.EntityFrameworkCore;
44
global using Microsoft.EntityFrameworkCore;

src/Dispatcher/MASA.Contrib.Dispatcher.Events/EventBus.cs

+8
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ public async Task PublishAsync<TEvent>(TEvent @event) where TEvent : IEvent
5050
}
5151

5252
public IEnumerable<Type> GetAllEventTypes() => _options.GetAllEventTypes();
53+
54+
public async Task CommitAsync(CancellationToken cancellationToken = default)
55+
{
56+
if (_unitOfWork is null)
57+
throw new ArgumentNullException(nameof(IUnitOfWork), "You need to UseUoW when adding services");
58+
59+
await _unitOfWork.CommitAsync(cancellationToken);
60+
}
5361
}

src/Dispatcher/MASA.Contrib.Dispatcher.Events/Internal/Middleware/TransactionMiddleware.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,9 @@ public async Task HandleAsync(TEvent @event, EventHandlerDelegate next)
1818

1919
if (@event is ITransaction transactionEvent)
2020
{
21-
if (transactionEvent.UnitOfWork != null)
21+
if (transactionEvent.UnitOfWork != null && transactionEvent.UnitOfWork.TransactionHasBegun)
2222
{
23-
if (transactionEvent.UnitOfWork.TransactionHasBegun)
24-
{
25-
await transactionEvent.UnitOfWork.CommitAsync();
26-
}
27-
else
28-
{
29-
await transactionEvent.UnitOfWork.SaveChangesAsync();
30-
}
23+
await transactionEvent.UnitOfWork.CommitAsync();
3124
}
3225
}
3326
}

0 commit comments

Comments
 (0)