Skip to content

Commit

Permalink
feat: optimizing assembly assignment (#14)
Browse files Browse the repository at this point in the history
* chore: update readme

* Merge branch 'docs/contrib' of...

* fix: Fix the problem of failing to get context after enabling soft delete

* Configuration and UnitTest

* chore: support net6.0

* Doc/contrib

* Feature/optimize

* chore: add package CI

* chore: update library package

* chore: add Codecov

* chore: update codecov

* chore: update codecov

* docs: add codecov badge

* chore: codecov ignore tests

* chore: update codecov

* chore: update codecov

* Update packge.yml

* Feature/ci

* 🆕 feat(minimal-apis): Improve MapGet, MapPost, MapPut and MapDelete with BaseUri prop

* 🐛 fix: Combine baseUri and customUri

* Update .gitlab-ci.yml

* 更新.gitlab-ci.yml文件

* Delete .gitlab-ci.yml

* chore: change fileName

* chore: update dapr library package

* chore: change readme

* chore: Added a solution to the failure to obtain the Event relationship chain

* Fix/event

* add ghpackageconfig

* Update package_push_github.yml

* Update package_push_nuget.org.yml

* Update nuget.config

* Update nuget.config

* Update package_push_nuget.org.yml

* Update package_push_github.yml

* Update nuget.config

* chore: Modify the introduction of Uow usage documentation (#3)

* chore: Modify the introduction of Uow usage documentation

* chore: Remove invalid comments

* Update package_push_github.yml

* Update nuget.config

* feat:event bus

* chore: Support local message retry

* chore: add retry record

* chore: Change the current time to Utc time

* chore: Optimize background tasks

* chore: Increase local message retry

* chore: Add local queue to support short retry

* chore: add retry retry Policy Documentation

* chore: Upgrade the base library

* chore: 1. Adjust EventBus to automatically execute savechange

          2. UoW supports Dispose
          3. Simplify the writing of Event, Command, Query, IntegrationEvent, etc.

* chore: Open transactions are controlled by Repository

* chore: adjust UnitOfWork and localmessage

* chore: add EventBus doc

* chore: Add local message table log

* chore: Adjust retry configuration

* chore: code review modification

* chore: Get current time support modification

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Update MASA.BuildingBlocks.DDD.Domain package version

* chore: add JsonIgnore and adjust unittest

* chore: code review modification

* chore: Adjust the writing method of CheckAndOpenTransaction to simplify nested if

* chore: Change the parameter description, change Task.Delay to Thread.Sleep

* fix: Fixed an error in the PublishQueueAsync method in the IDomainEventBus

* fix: Fixed an error in the PublishQueueAsync method in the IDomainEventBus class

* chore: remove using by class

* Squashed 'src/MASA.BuildingBlocks/' content from commit b6a2d36

git-subtree-dir: src/MASA.BuildingBlocks
git-subtree-split: b6a2d366dae89cef24d452ae2ad4d4debe252ae6

* update src

* add buildingblock

* update action

* Delete package_push_github.yml

* Update package_push_nuget.org.yml

* refactor: project references building blocks

* chore: Support local message retry

* chore: add retry record

* chore: Change the current time to Utc time

* chore: Optimize background tasks

* chore: Increase local message retry

* chore: Add local queue to support short retry

* chore: add retry retry Policy Documentation

* chore: Upgrade the base library

* chore: 1. Adjust EventBus to automatically execute savechange

          2. UoW supports Dispose
          3. Simplify the writing of Event, Command, Query, IntegrationEvent, etc.

* chore: Open transactions are controlled by Repository

* chore: adjust UnitOfWork and localmessage

* chore: add EventBus doc

* chore: Add local message table log

* chore: Adjust retry configuration

* chore: code review modification

* chore: Get current time support modification

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Update MASA.BuildingBlocks.DDD.Domain package version

* chore: add JsonIgnore and adjust unittest

* chore: code review modification

* chore: Adjust the writing method of CheckAndOpenTransaction to simplify nested if

* chore: Change the parameter description, change Task.Delay to Thread.Sleep

* Update package_push_github.yml

* chore: update library package and filter the local failure message just executed

* chore: update library package

* Update package_push_github.yml

* Update package_push_github.yml

* chore: ILogger changed to optional

* chore: add Logging by integrationEventBus

* chore: Handle background local message tasks

* refactor: Handling null exceptions, warnings, and Logger changed to not requiredHandling null exceptions, warnings, and Logger changed to not required

* chore: update library package

* chore: adjust DelayAsync

* chore: Replacement interval in seconds

* chore: delete summodule

* chore: add MASA.BuildingBlocks submodules

* chore: Change parameter remarks

* chore: Adjust package references

* chore: remove MASA.BuildingBlock package

* Update package_push_nuget.org.yml

* Update package_push_nuget.org.yml

* refactor: change MASA.Contrib to Masa.Contrib (#11)

* tag: 0.3.0-preview.1 (#10)

* chore: update readme

* Merge branch 'docs/contrib' of...

* fix: Fix the problem of failing to get context after enabling soft delete

* Configuration and UnitTest

* chore: support net6.0

* Doc/contrib

* Feature/optimize

* chore: add package CI

* chore: update library package

* chore: add Codecov

* chore: update codecov

* chore: update codecov

* docs: add codecov badge

* chore: codecov ignore tests

* chore: update codecov

* chore: update codecov

* Update packge.yml

* Feature/ci

* 🆕 feat(minimal-apis): Improve MapGet, MapPost, MapPut and MapDelete with BaseUri prop

* 🐛 fix: Combine baseUri and customUri

* Update .gitlab-ci.yml

* 更新.gitlab-ci.yml文件

* Delete .gitlab-ci.yml

* chore: change fileName

* chore: update dapr library package

* chore: change readme

* chore: Added a solution to the failure to obtain the Event relationship chain

* Fix/event

* add ghpackageconfig

* Update package_push_github.yml

* Update package_push_nuget.org.yml

* Update nuget.config

* Update nuget.config

* Update package_push_nuget.org.yml

* Update package_push_github.yml

* Update nuget.config

* chore: Modify the introduction of Uow usage documentation (#3)

* chore: Modify the introduction of Uow usage documentation

* chore: Remove invalid comments

* Update package_push_github.yml

* Update nuget.config

* feat:event bus

* chore: Support local message retry

* chore: add retry record

* chore: Change the current time to Utc time

* chore: Optimize background tasks

* chore: Increase local message retry

* chore: Add local queue to support short retry

* chore: add retry retry Policy Documentation

* chore: Upgrade the base library

* chore: 1. Adjust EventBus to automatically execute savechange

          2. UoW supports Dispose
          3. Simplify the writing of Event, Command, Query, IntegrationEvent, etc.

* chore: Open transactions are controlled by Repository

* chore: adjust UnitOfWork and localmessage

* chore: add EventBus doc

* chore: Add local message table log

* chore: Adjust retry configuration

* chore: code review modification

* chore: Get current time support modification

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Update MASA.BuildingBlocks.DDD.Domain package version

* chore: add JsonIgnore and adjust unittest

* chore: code review modification

* chore: Adjust the writing method of CheckAndOpenTransaction to simplify nested if

* chore: Change the parameter description, change Task.Delay to Thread.Sleep

* fix: Fixed an error in the PublishQueueAsync method in the IDomainEventBus

* fix: Fixed an error in the PublishQueueAsync method in the IDomainEventBus class

* chore: remove using by class

* Squashed 'src/MASA.BuildingBlocks/' content from commit b6a2d36

git-subtree-dir: src/MASA.BuildingBlocks
git-subtree-split: b6a2d366dae89cef24d452ae2ad4d4debe252ae6

* update src

* add buildingblock

* update action

* Delete package_push_github.yml

* Update package_push_nuget.org.yml

* refactor: project references building blocks

* chore: Support local message retry

* chore: add retry record

* chore: Change the current time to Utc time

* chore: Optimize background tasks

* chore: Increase local message retry

* chore: Add local queue to support short retry

* chore: add retry retry Policy Documentation

* chore: Upgrade the base library

* chore: 1. Adjust EventBus to automatically execute savechange

          2. UoW supports Dispose
          3. Simplify the writing of Event, Command, Query, IntegrationEvent, etc.

* chore: Open transactions are controlled by Repository

* chore: adjust UnitOfWork and localmessage

* chore: add EventBus doc

* chore: Add local message table log

* chore: Adjust retry configuration

* chore: code review modification

* chore: Get current time support modification

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Change the file name ConfigurationAPIClient -> ConfigurationApiClient

Change the file name ConfigurationAPIManage -> ConfigurationApiManage
EntityState overload

* chore: Update MASA.BuildingBlocks.DDD.Domain package version

* chore: add JsonIgnore and adjust unittest

* chore: code review modification

* chore: Adjust the writing method of CheckAndOpenTransaction to simplify nested if

* chore: Change the parameter description, change Task.Delay to Thread.Sleep

* Update package_push_github.yml

* chore: update library package and filter the local failure message just executed

* chore: update library package

* Update package_push_github.yml

* Update package_push_github.yml

* chore: ILogger changed to optional

* chore: add Logging by integrationEventBus

* chore: Handle background local message tasks

* refactor: Handling null exceptions, warnings, and Logger changed to not requiredHandling null exceptions, warnings, and Logger changed to not required

* chore: update library package

* chore: adjust DelayAsync

* chore: Replacement interval in seconds

* chore: delete summodule

* chore: add MASA.BuildingBlocks submodules

* chore: Change parameter remarks

* chore: Adjust package references

* chore: remove MASA.BuildingBlock package

* Update package_push_nuget.org.yml

Co-authored-by: zhenlei520 <[email protected]>
Co-authored-by: zhenlei520 <[email protected]>
Co-authored-by: 朱嵘 <[email protected]>
Co-authored-by: capdiem <[email protected]>
Co-authored-by: 曹尤先 <[email protected]>
Co-authored-by: zhenlei520 <[email protected]>
Co-authored-by: 王达 <[email protected]>
Co-authored-by: PollosD <[email protected]>

* Update package_push_nuget.org.yml

* Update package_push_nuget.org.yml

* chore: delete submodule

* chore: add submodule

* refactor: change MASA.Contrib to Masa.Contrib

* refactor: change MASA.Contrib to Masa.Contrib

* chore: update readme

* chore: change readme

* chore: change readme

Co-authored-by: 鬼谷子 <[email protected]>
Co-authored-by: zhenlei520 <[email protected]>
Co-authored-by: zhenlei520 <[email protected]>
Co-authored-by: 朱嵘 <[email protected]>
Co-authored-by: capdiem <[email protected]>
Co-authored-by: 曹尤先 <[email protected]>
Co-authored-by: 王达 <[email protected]>
Co-authored-by: PollosD <[email protected]>

* chore: update submodule

* chore: update git workflow

* chore: Event Unified Assembly

* chore: update submodule

* chore: delete empty line

* chore: Removed aggregate root must have no-argument constructor restriction

* chore: Removed aggregate root must have no-argument constructor restriction

* chore: Change unit test method to synchronous method

* test: Add Masa.Contrib.Dispatcher.IntegrationEvents.Dapr unit test

* test: Add Masa.Contrib.Dispatcher.IntegrationEvents.Dapr unit test

* test: adjust unit test

* chore: update library package

* test: adjust unit test

* chore: Repository removes aggregate root limit

Co-authored-by: dodd <[email protected]>
Co-authored-by: zhenlei520 <[email protected]>
Co-authored-by: zhenlei520 <[email protected]>
Co-authored-by: 朱嵘 <[email protected]>
Co-authored-by: capdiem <[email protected]>
Co-authored-by: 曹尤先 <[email protected]>
Co-authored-by: 王达 <[email protected]>
Co-authored-by: PollosD <[email protected]>
  • Loading branch information
9 people authored Mar 8, 2022
1 parent 80847ea commit 12c3df0
Show file tree
Hide file tree
Showing 64 changed files with 1,443 additions and 824 deletions.
33 changes: 0 additions & 33 deletions Masa.Contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Configuration.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Configuration.MountErrorSectionAutoMap.Tests", "test\Masa.Contrib.Configuration.MountErrorSectionAutoMap.Tests\Masa.Contrib.Configuration.MountErrorSectionAutoMap.Tests.csproj", "{427822F2-7A20-4E3A-B45C-43CE855003C1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Ddd.Domain.Repository.EF.CombinedKeysNoFind.Tests", "test\Masa.Contrib.Ddd.Domain.Repository.EF.CombinedKeysNoFindTests\Masa.Contrib.Ddd.Domain.Repository.EF.CombinedKeysNoFind.Tests.csproj", "{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Ddd.Domain.Repository.EF.CombinedKeys.Tests", "test\Masa.Contrib.Ddd.Domain.Repository.EF.CombinedKeys.Tests\Masa.Contrib.Ddd.Domain.Repository.EF.CombinedKeys.Tests.csproj", "{A4DE46BD-1FA4-494B-80DA-6EB370686F17}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Ddd.Domain.Repository.EF.CustomRepository.Tests", "test\Masa.Contrib.Ddd.Domain.Repository.EF.CustomRepository.Tests\Masa.Contrib.Ddd.Domain.Repository.EF.CustomRepository.Tests.csproj", "{7909A736-6C1E-4622-9BE7-37EF0839FA05}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Ddd.Domain.Repository.EF.Entity.Tests", "test\Masa.Contrib.Ddd.Domain.Repository.EF.Entity.Tests\Masa.Contrib.Ddd.Domain.Repository.EF.Entity.Tests.csproj", "{71E02AFA-06A0-4527-923C-6666B3D66542}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests", "test\Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests\Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests.csproj", "{1A86AE9B-A57D-43D2-9E8C-5ED0C1E6041C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildingBlocks", "BuildingBlocks", "{DC578D74-98F0-4F19-A230-CFA8DAEE0AF1}"
Expand Down Expand Up @@ -412,22 +406,6 @@ Global
{427822F2-7A20-4E3A-B45C-43CE855003C1}.Release|Any CPU.Build.0 = Release|Any CPU
{427822F2-7A20-4E3A-B45C-43CE855003C1}.Release|x64.ActiveCfg = Release|Any CPU
{427822F2-7A20-4E3A-B45C-43CE855003C1}.Release|x64.Build.0 = Release|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Debug|x64.ActiveCfg = Debug|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Debug|x64.Build.0 = Debug|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Release|Any CPU.Build.0 = Release|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Release|x64.ActiveCfg = Release|Any CPU
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98}.Release|x64.Build.0 = Release|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Debug|x64.ActiveCfg = Debug|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Debug|x64.Build.0 = Debug|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Release|Any CPU.Build.0 = Release|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Release|x64.ActiveCfg = Release|Any CPU
{A4DE46BD-1FA4-494B-80DA-6EB370686F17}.Release|x64.Build.0 = Release|Any CPU
{7909A736-6C1E-4622-9BE7-37EF0839FA05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7909A736-6C1E-4622-9BE7-37EF0839FA05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7909A736-6C1E-4622-9BE7-37EF0839FA05}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -436,14 +414,6 @@ Global
{7909A736-6C1E-4622-9BE7-37EF0839FA05}.Release|Any CPU.Build.0 = Release|Any CPU
{7909A736-6C1E-4622-9BE7-37EF0839FA05}.Release|x64.ActiveCfg = Release|Any CPU
{7909A736-6C1E-4622-9BE7-37EF0839FA05}.Release|x64.Build.0 = Release|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Debug|x64.ActiveCfg = Debug|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Debug|x64.Build.0 = Debug|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Release|Any CPU.Build.0 = Release|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Release|x64.ActiveCfg = Release|Any CPU
{71E02AFA-06A0-4527-923C-6666B3D66542}.Release|x64.Build.0 = Release|Any CPU
{1A86AE9B-A57D-43D2-9E8C-5ED0C1E6041C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A86AE9B-A57D-43D2-9E8C-5ED0C1E6041C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A86AE9B-A57D-43D2-9E8C-5ED0C1E6041C}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -578,10 +548,7 @@ Global
{5A163042-B03A-4063-85FF-22D4C5BB5B90} = {38E6C400-90C0-493E-9266-C1602E229F1B}
{84EFF9E1-6852-458F-8D57-62E3F084EA0F} = {9EEE31DA-3165-4CB3-AAE9-27CC3A4DE669}
{427822F2-7A20-4E3A-B45C-43CE855003C1} = {9EEE31DA-3165-4CB3-AAE9-27CC3A4DE669}
{99067BDF-2C6A-47F8-913D-3FF9F2A69F98} = {880E8263-AECC-4793-BD28-7CD03650D124}
{A4DE46BD-1FA4-494B-80DA-6EB370686F17} = {880E8263-AECC-4793-BD28-7CD03650D124}
{7909A736-6C1E-4622-9BE7-37EF0839FA05} = {880E8263-AECC-4793-BD28-7CD03650D124}
{71E02AFA-06A0-4527-923C-6666B3D66542} = {880E8263-AECC-4793-BD28-7CD03650D124}
{1A86AE9B-A57D-43D2-9E8C-5ED0C1E6041C} = {2BE750A5-8AC7-457C-9BB2-6E3D5E2D23B8}
{DC578D74-98F0-4F19-A230-CFA8DAEE0AF1} = {42DF7AAC-362C-48F4-B76A-BDEEEFF17CC9}
{374B7E56-A815-4F56-A4C2-6094B5A97EE7} = {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Masa.Utils.Caching.DistributedMemory" Version="0.3.0" />
<PackageReference Include="Masa.Utils.Caching.Redis" Version="0.3.0" />
<PackageReference Include="Masa.Utils.Caller.Core" Version="0.3.0" />
<PackageReference Include="Masa.Utils.Caller.HttpClient" Version="0.3.0" />
<PackageReference Include="Masa.Utils.Caching.DistributedMemory" Version="0.3.1" />
<PackageReference Include="Masa.Utils.Caching.Redis" Version="0.3.1" />
<PackageReference Include="Masa.Utils.Caller.Core" Version="0.3.1" />
<PackageReference Include="Masa.Utils.Caller.HttpClient" Version="0.3.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Masa.Utils.Data.EntityFrameworkCore" Version="0.3.0" />
<PackageReference Include="Masa.Utils.Data.EntityFrameworkCore" Version="0.3.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Masa.Utils.Data.EntityFrameworkCore" Version="0.3.0" />
<PackageReference Include="Masa.Utils.Data.EntityFrameworkCore" Version="0.3.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Data/Masa.Contrib.Data.UoW.EF/UnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Masa.Contrib.Data.UoW.EF;

public class UnitOfWork<TDbContext> : IAsyncDisposable, IUnitOfWork
public class UnitOfWork<TDbContext> : IUnitOfWork
where TDbContext : MasaDbContext
{
public DbTransaction Transaction
Expand All @@ -21,9 +21,9 @@ public DbTransaction Transaction

public bool DisableRollbackOnFailure { get; set; }

public EntityState EntityState { get; set; }
public EntityState EntityState { get; set; } = EntityState.UnChanged;

public CommitState CommitState { get; set; }
public CommitState CommitState { get; set; } = CommitState.Commited;

public bool UseTransaction { get; set; } = true;

Expand All @@ -40,7 +40,7 @@ public UnitOfWork(TDbContext dbContext, ILogger<UnitOfWork<TDbContext>>? logger
public async Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
await _context.SaveChangesAsync(cancellationToken);
EntityState = EntityState.Unchanged;
EntityState = EntityState.UnChanged;
}

public async Task CommitAsync(CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,70 @@ namespace Masa.Contrib.Ddd.Domain.Repository.EF.Internal;

internal static class ServiceCollectionRepositoryExtensions
{
/// <summary>
/// The relationship between entity and keys
/// </summary>
public static Dictionary<Type, string[]> Relations = new();

public static IServiceCollection TryAddRepository<TDbContext>(
this IServiceCollection services,
params Assembly[] assemblies)
where TDbContext : DbContext
this IServiceCollection services,
params Assembly[] assemblies)
where TDbContext : DbContext
{
if (assemblies == null || assemblies.Length == 0)
{
throw new ArgumentNullException(nameof(assemblies));
}

var allTypes = assemblies.SelectMany(assembly => assembly.GetTypes());
var allTypes = assemblies.SelectMany(assembly => assembly.GetTypes()).ToList();
var entityTypes = allTypes.Where(type => type.IsAggregateRootEntity());
foreach (var entityType in entityTypes)
{
var repositoryInterfaceType = typeof(IRepository<>).MakeGenericType(entityType);

services.TryAddAddDefaultRepository(repositoryInterfaceType, GetRepositoryImplementationType(typeof(TDbContext), entityType));
services.TryAddCustomRepository(repositoryInterfaceType, allTypes);

services.TryAddCustomRepository(repositoryInterfaceType, allTypes.ToArray());

var keys = GetKeys(entityType);
CheckKeys(entityType, keys);
Relations.TryAdd(entityType, keys);
if (typeof(IEntity<>).IsGenericInterfaceAssignableFrom(entityType))
{
var fieldType = entityType.GetProperty("Id")!.PropertyType;
repositoryInterfaceType = typeof(IRepository<,>).MakeGenericType(entityType, fieldType);
services.TryAddAddDefaultRepository(repositoryInterfaceType,
GetRepositoryImplementationType(typeof(TDbContext), entityType, fieldType));
services.TryAddCustomRepository(repositoryInterfaceType, allTypes);
}
}

return services;
}

private static string[] GetKeys(Type entityType)
{
IAggregateRoot aggregateRoot;
try
{
var constructorInfo = entityType
.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault(con => !con.CustomAttributes.Any());

if (constructorInfo == null)
throw new ArgumentNullException("The entity needs to have an empty constructor");

aggregateRoot = (IAggregateRoot)Activator.CreateInstance(entityType, constructorInfo.IsPrivate)!;
}
catch (Exception)
{
throw new ArgumentNullException("The entity needs to have an empty constructor");
}

var keys = aggregateRoot.GetKeys().Select(k => k.Name).ToArray();
if (keys.Length != keys.Where(key => !string.IsNullOrEmpty(key)).Distinct().Count())
throw new ArgumentException("The joint primary key cannot be empty");

return keys;
}

/// <summary>
/// Check if the combined primary key is correct
/// </summary>
private static void CheckKeys(Type entityType, string[] fields)
{
foreach (var field in fields)
{
if (!entityType.GetProperties().Any(p => p.Name.Equals(field, StringComparison.OrdinalIgnoreCase))!)
throw new ArgumentException("Check if the combined primary key is correct");
}
}

private static bool IsAggregateRootEntity(this Type type)
=> type.IsClass && !type.IsGenericType && !type.IsAbstract && type != typeof(AggregateRoot) && type != typeof(Entity) && typeof(IAggregateRoot).IsAssignableFrom(type);
=> type.IsClass && !type.IsGenericType && !type.IsAbstract && type != typeof(AggregateRoot) && type != typeof(Entity) &&
typeof(IAggregateRoot).IsAssignableFrom(type);

private static IServiceCollection TryAddCustomRepository(this IServiceCollection services, Type repositoryInterfaceType, Type[] allTypes)
private static void TryAddCustomRepository(this IServiceCollection services, Type repositoryInterfaceType, List<Type> allTypes)
{
var customerRepositoryInterfaceTypes = allTypes.Where(type => type.GetInterfaces().Any(t => t == repositoryInterfaceType) && type.IsInterface && !type.IsGenericType);
var customerRepositoryInterfaceTypes = allTypes.Where(type
=> type.GetInterfaces().Any(t => t == repositoryInterfaceType) && type.IsInterface && !type.IsGenericType);
foreach (var customerRepositoryInterfaceType in customerRepositoryInterfaceTypes)
{
var customerRepositoryImplementationTypes = allTypes.Where(type => type.IsClass && customerRepositoryInterfaceType.IsAssignableFrom(type)).ToList();
var customerRepositoryImplementationTypes =
allTypes.Where(type => type.IsClass && customerRepositoryInterfaceType.IsAssignableFrom(type)).ToList();
if (customerRepositoryImplementationTypes.Count != 1)
{
throw new NotSupportedException($"The number of types of {customerRepositoryInterfaceType.FullName} implementation classes must be 1");
throw new NotSupportedException(
$"The number of types of {customerRepositoryInterfaceType.FullName} implementation classes must be 1");
}
services.TryAddScoped(customerRepositoryInterfaceType, customerRepositoryImplementationTypes.FirstOrDefault()!);
}
return services;
}

private static IServiceCollection TryAddAddDefaultRepository(this IServiceCollection services, Type repositoryInterfaceType, Type repositoryImplementationType)
private static void TryAddAddDefaultRepository(this IServiceCollection services, Type repositoryInterfaceType,
Type repositoryImplementationType)
{
if (repositoryInterfaceType.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddScoped(repositoryInterfaceType, repositoryImplementationType);
}
return services;
}

public static Type GetRepositoryImplementationType(Type dbContextType, Type entityType)
private static Type GetRepositoryImplementationType(Type dbContextType, Type entityType)
=> typeof(Repository<,>).MakeGenericType(dbContextType, entityType);

private static Type GetRepositoryImplementationType(Type dbContextType, Type entityType, Type keyType)
=> typeof(Repository<,,>).MakeGenericType(dbContextType, entityType, keyType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Masa.Contrib.Ddd.Domain.Repository.EF.Internal;

internal static class TypeExtensions
{
public static bool IsConcrete(this Type type) => !type.GetTypeInfo().IsAbstract && !type.GetTypeInfo().IsInterface;

public static bool IsGenericInterfaceAssignableFrom(this Type eventHandlerType, Type type) =>
type.IsConcrete() &&
type.GetInterfaces().Any(t => t.GetTypeInfo().IsGenericType && t.GetGenericTypeDefinition() == eventHandlerType);
}
38 changes: 21 additions & 17 deletions src/Ddd/Masa.Contrib.Ddd.Domain.Repository.EF/Repository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace Masa.Contrib.Ddd.Domain.Repository.EF;

public class Repository<TDbContext, TEntity> : BaseRepository<TEntity>
where TEntity : class, IAggregateRoot
public class Repository<TDbContext, TEntity> :
BaseRepository<TEntity>
where TEntity : class, IEntity
where TDbContext : DbContext
{
protected readonly TDbContext _context;
Expand Down Expand Up @@ -73,19 +74,10 @@ public override Task CommitAsync(CancellationToken cancellationToken = default)
public override void Dispose() => _context.Dispose();

public override Task<TEntity?> FindAsync(
object?[]? keyValues,
IEnumerable<KeyValuePair<string, object>> keyValues,
CancellationToken cancellationToken = default)
{
if (keyValues == null)
return Task.FromResult(default(TEntity?));

var keys = GetKeys(typeof(TEntity));
Dictionary<string, object> fields = new();
for (var i = 0; i < keys.Length; i++)
{
fields.Add(keys[i], keyValues[i]!);
}

Dictionary<string, object> fields = new(keyValues);
return _context.Set<TEntity>().IgnoreQueryFilters().GetQueryable(fields).FirstOrDefaultAsync(cancellationToken);
}

Expand Down Expand Up @@ -124,7 +116,7 @@ public override Task<List<TEntity>> GetPaginatedListAsync(
Dictionary<string, bool>? sorting,
CancellationToken cancellationToken = default)
{
sorting ??= new Dictionary<string, bool>(GetKeys(typeof(TEntity)).Select(key => new KeyValuePair<string, bool>(key, false)));
sorting ??= new Dictionary<string, bool>();

return _context.Set<TEntity>().OrderBy(sorting).Skip(skip).Take(take).ToListAsync(cancellationToken);
}
Expand All @@ -145,7 +137,7 @@ public override Task<List<TEntity>> GetPaginatedListAsync(
Dictionary<string, bool>? sorting,
CancellationToken cancellationToken = default)
{
sorting ??= new Dictionary<string, bool>(GetKeys(typeof(TEntity)).Select(key => new KeyValuePair<string, bool>(key, false)));
sorting ??= new Dictionary<string, bool>();

return _context.Set<TEntity>().Where(predicate).OrderBy(sorting).Skip(skip).Take(take).ToListAsync(cancellationToken);
}
Expand Down Expand Up @@ -207,7 +199,19 @@ private void CheckAndOpenTransaction()
}
CommitState = CommitState.UnCommited;
}
}

public class Repository<TDbContext, TEntity, TKey> :
Repository<TDbContext, TEntity>,
IRepository<TEntity, TKey>, IUnitOfWork
where TEntity : class, IEntity<TKey>
where TDbContext : DbContext
where TKey : IComparable
{
public Repository(TDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork)
{
}

protected string[] GetKeys(Type entityType)
=> ServiceCollectionRepositoryExtensions.Relations[entityType]!;
public Task<TEntity?> FindAsync(TKey id)
=> _context.Set<TEntity>().FirstOrDefaultAsync(entity => entity.Id.Equals(id));
}
2 changes: 0 additions & 2 deletions src/Ddd/Masa.Contrib.Ddd.Domain.Repository.EF/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
global using Microsoft.EntityFrameworkCore.Storage;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using Microsoft.Extensions.Logging;
global using System.Collections.Concurrent;
global using System.Data.Common;
global using System.Linq.Expressions;
global using System.Reflection;
Expand Down
Loading

0 comments on commit 12c3df0

Please sign in to comment.