From 11c54401ca15e0c65de3f853e8739162faa22af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=AC=E9=9B=A8=E5=A3=B0?= Date: Tue, 8 Mar 2022 09:27:54 +0800 Subject: [PATCH] refactor: Repository removes AggregateRoot limit (#22) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: add license * chore: add readme * chore: update readme * chore: update readme * chore: adjust EventBus and Prevent duplicate sending * Feature/uow * Feature/configuration * Fix/configuration * chore: support net6.0 * add packege push nuget * add packege push nuget * change pipeline * chore: fix != * Feature/optimize * chore: add workflow_dispatch * chore: update CI PackageVersion * Feature/ci * chore: remove nuget config * chore: add code map * chore: Id of event,CreationTime increase JsonIgnore * Feature/ghpackageconfig * feat(Data): add AutoComplete * chore: auto complete init * chore: AutoComplete init * chore: autocomplete init * chore: Change AutoComplete * chore: Adjust SetAsync * chore: adjust MASA.BuildingBlocks.SearchEngine.AutoComplete * chore: adjust SetResponse * chore: Remove generic constraints * chore: Adjust the response value of the Set method * chore: adjust MASA.BuildingBlocks.SearchEngine.AutoComplete * chore: add MASA.BuildingBlocks.SearchEngine.AutoComplete * chore: Adjust the class name and AudioCompleteDocument Co-authored-by: zhenlei520 * Update nuget.config * Update nuget.config * Update nuget.config * Update package_push_github.yml * chore: Modify the current time to Utc time * chore: Modify the current time to Utc time * chore: fix warning * chore: Add GetCurrentTime method * chore: Adjust assignment * feat(IntegrationEvents): IntegrationEvent adds retry * chore: adjust RetrieveEventLogsFailedToPublishAsync methods * chore: add retry support * chore: remove local message retry logging * chore: add added delete expired messages * chore: Support cross-process message retry * chore: Adjustment format * chore: Adjust parameter names * chore: Adjust ICommand to support transaction autocommit * chore: Add default parameters * chore: Modify the maximum number of retries * chore: add entity state * chore: add entity state * chore: change method description * chore:adjust the MASA.BuildingBlocks.Configuration file structure Co-authored-by: zhenlei520 * refactor(UoW): ConfigurationApiClient * chore: add entity state * chore: change method description * chore:adjust the MASA.BuildingBlocks.Configuration file structure * Change the file name ConfigurationAPIClient -> ConfigurationApiClient EntityState changed to virtual method Co-authored-by: zhenlei520 * feat(Domain): add CommitState * feat: supports modification time (#8) * feat: supports modification time IRepository adds an AnyAsync method * chore: add minimum retry interval * chore: IRepository removes the any method, IRepository only provides basic methods, and other functions are implemented by the user * feat: logger changed to optional (#9) * Delete package_push_github.yml * update action * Update packge_push_nuget.org.yml * Delete packge_push_nuget.org.yml * tag: 0.3.0-preview.1 (#11) * chore: update readme * tag: 0.3.0-preview.1 (#10) * chore: add license * chore: add readme * chore: update readme * chore: update readme * chore: adjust EventBus and Prevent duplicate sending * Feature/uow * Feature/configuration * Fix/configuration * chore: support net6.0 * add packege push nuget * add packege push nuget * change pipeline * chore: fix != * Feature/optimize * chore: add workflow_dispatch * chore: update CI PackageVersion * Feature/ci * chore: remove nuget config * chore: add code map * chore: Id of event,CreationTime increase JsonIgnore * Feature/ghpackageconfig * feat(Data): add AutoComplete * chore: auto complete init * chore: AutoComplete init * chore: autocomplete init * chore: Change AutoComplete * chore: Adjust SetAsync * chore: adjust MASA.BuildingBlocks.SearchEngine.AutoComplete * chore: adjust SetResponse * chore: Remove generic constraints * chore: Adjust the response value of the Set method * chore: adjust MASA.BuildingBlocks.SearchEngine.AutoComplete * chore: add MASA.BuildingBlocks.SearchEngine.AutoComplete * chore: Adjust the class name and AudioCompleteDocument Co-authored-by: zhenlei520 * Update nuget.config * Update nuget.config * Update nuget.config * Update package_push_github.yml * chore: Modify the current time to Utc time * chore: Modify the current time to Utc time * chore: fix warning * chore: Add GetCurrentTime method * chore: Adjust assignment * feat(IntegrationEvents): IntegrationEvent adds retry * chore: adjust RetrieveEventLogsFailedToPublishAsync methods * chore: add retry support * chore: remove local message retry logging * chore: add added delete expired messages * chore: Support cross-process message retry * chore: Adjustment format * chore: Adjust parameter names * chore: Adjust ICommand to support transaction autocommit * chore: Add default parameters * chore: Modify the maximum number of retries * chore: add entity state * chore: add entity state * chore: change method description * chore:adjust the MASA.BuildingBlocks.Configuration file structure Co-authored-by: zhenlei520 * refactor(UoW): ConfigurationApiClient * chore: add entity state * chore: change method description * chore:adjust the MASA.BuildingBlocks.Configuration file structure * Change the file name ConfigurationAPIClient -> ConfigurationApiClient EntityState changed to virtual method Co-authored-by: zhenlei520 * feat(Domain): add CommitState * feat: supports modification time (#8) * feat: supports modification time IRepository adds an AnyAsync method * chore: add minimum retry interval * chore: IRepository removes the any method, IRepository only provides basic methods, and other functions are implemented by the user * feat: logger changed to optional (#9) * Delete package_push_github.yml * update action * Update packge_push_nuget.org.yml * Delete packge_push_nuget.org.yml Co-authored-by: zhenlei520 Co-authored-by: zhenlei520 Co-authored-by: unknown Co-authored-by: zhenlei520 Co-authored-by: 王达 Co-authored-by: PollosD <55781685+PollosD@users.noreply.github.com> Co-authored-by: 谷首道 Co-authored-by: zhenlei520 Co-authored-by: zhenlei520 Co-authored-by: unknown Co-authored-by: zhenlei520 Co-authored-by: 王达 Co-authored-by: PollosD <55781685+PollosD@users.noreply.github.com> * refactor: remove MASA * refactor: MASA.BuildingBlocks to Masa.BuildingBlocks (#17) * refactor: MASA.BuildingBlocks to Masa.BuildingBlocks * chore: delete .vs * chore: ignore .vs * refactor: change Masa.BuildingBlocks.DDD to Masa.BuildingBlocks.Ddd (#18) * refactor: move Masa.BuildingBlocks.DDD to Masa.BuildingBlocks.Ddd move Masa.BuildingBlocks.ReadWriteSpliting.CQRS to Masa.BuildingBlocks.ReadWriteSpliting.Cqrs * refactor: move Masa.BuildingBlocks.DDD to Masa.BuildingBlocks.Ddd move Masa.BuildingBlocks.ReadWriteSpliting.CQRS to Masa.BuildingBlocks.ReadWriteSpliting.Cqrs * feat: Removed aggregate root must have no-argument constructor restriction Domain model entities remove public set methods * test: adjust unit test * chore: Repository removes aggregate root limit * chore: Repository removes aggregate root limit Co-authored-by: dodd <358683537@qq.com> Co-authored-by: zhenlei520 Co-authored-by: zhenlei520 Co-authored-by: unknown Co-authored-by: 王达 Co-authored-by: PollosD <55781685+PollosD@users.noreply.github.com> Co-authored-by: 谷首道 --- .../Repositories/BaseRepository.cs | 42 ++++++++--------- .../Repositories/IRepository.cs | 46 ++++++++++--------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/BaseRepository.cs b/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/BaseRepository.cs index 52b7d7c..55c382e 100644 --- a/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/BaseRepository.cs +++ b/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/BaseRepository.cs @@ -1,13 +1,13 @@ namespace Masa.BuildingBlocks.Ddd.Domain.Repositories; -public abstract class BaseRepository : - IRepository, IUnitOfWork - where TAggregateRoot : class, IAggregateRoot +public abstract class BaseRepository : + IRepository, IUnitOfWork + where TEntity : class, IEntity { #region IRepository - public abstract ValueTask AddAsync(TAggregateRoot entity, CancellationToken cancellationToken = default); + public abstract ValueTask AddAsync(TEntity entity, CancellationToken cancellationToken = default); - public virtual async Task AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) + public virtual async Task AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) { foreach (var entity in entities) { @@ -15,15 +15,15 @@ public virtual async Task AddRangeAsync(IEnumerable entities, Ca } } - public abstract Task FindAsync(IEnumerable> keyValues, CancellationToken cancellationToken = default); + public abstract Task FindAsync(IEnumerable> keyValues, CancellationToken cancellationToken = default); - public abstract Task FindAsync(Expression> predicate, CancellationToken cancellationToken = default); + public abstract Task FindAsync(Expression> predicate, CancellationToken cancellationToken = default); - public abstract Task RemoveAsync(TAggregateRoot entity, CancellationToken cancellationToken = default); + public abstract Task RemoveAsync(TEntity entity, CancellationToken cancellationToken = default); - public abstract Task RemoveAsync(Expression> predicate, CancellationToken cancellationToken = default); + public abstract Task RemoveAsync(Expression> predicate, CancellationToken cancellationToken = default); - public virtual async Task RemoveRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) + public virtual async Task RemoveRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) { foreach (var entity in entities) { @@ -31,9 +31,9 @@ public virtual async Task RemoveRangeAsync(IEnumerable entities, } } - public abstract Task UpdateAsync(TAggregateRoot entity, CancellationToken cancellationToken = default); + public abstract Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default); - public virtual async Task UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) + public virtual async Task UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) { foreach (var entity in entities) { @@ -41,19 +41,19 @@ public virtual async Task UpdateRangeAsync(IEnumerable entities, } } - public abstract Task> GetListAsync(CancellationToken cancellationToken = default); + public abstract Task> GetListAsync(CancellationToken cancellationToken = default); - public abstract Task> GetListAsync(Expression> predicate, CancellationToken cancellationToken = default); + public abstract Task> GetListAsync(Expression> predicate, CancellationToken cancellationToken = default); public abstract Task GetCountAsync(CancellationToken cancellationToken = default); - public abstract Task GetCountAsync(Expression> predicate, CancellationToken cancellationToken = default); + public abstract Task GetCountAsync(Expression> predicate, CancellationToken cancellationToken = default); - public abstract Task> GetPaginatedListAsync(int skip, int take, Dictionary? sorting, CancellationToken cancellationToken = default); + public abstract Task> GetPaginatedListAsync(int skip, int take, Dictionary? sorting, CancellationToken cancellationToken = default); - public abstract Task> GetPaginatedListAsync(Expression> predicate, int skip, int take, Dictionary? sorting, CancellationToken cancellationToken = default); + public abstract Task> GetPaginatedListAsync(Expression> predicate, int skip, int take, Dictionary? sorting, CancellationToken cancellationToken = default); - public virtual async Task> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default) + public virtual async Task> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default) { var result = await GetPaginatedListAsync( (options.Page - 1) * options.PageSize, @@ -64,7 +64,7 @@ public virtual async Task> GetPaginatedListAsync(P var total = await GetCountAsync(cancellationToken); - return new PaginatedList() + return new PaginatedList() { Total = total, Result = result, @@ -72,7 +72,7 @@ public virtual async Task> GetPaginatedListAsync(P }; } - public async Task> GetPaginatedListAsync(Expression> predicate, PaginatedOptions options, CancellationToken cancellationToken = default) + public async Task> GetPaginatedListAsync(Expression> predicate, PaginatedOptions options, CancellationToken cancellationToken = default) { var result = await GetPaginatedListAsync( predicate, @@ -84,7 +84,7 @@ public async Task> GetPaginatedListAsync(Expressio var total = await GetCountAsync(predicate, cancellationToken); - return new PaginatedList() + return new PaginatedList() { Total = total, Result = result, diff --git a/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/IRepository.cs b/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/IRepository.cs index 9a5faaf..bff5f8f 100644 --- a/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/IRepository.cs +++ b/src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/IRepository.cs @@ -1,71 +1,75 @@ namespace Masa.BuildingBlocks.Ddd.Domain.Repositories; -public interface IRepository - where TAggregateRoot : class, IAggregateRoot +public interface IRepository + where TEntity : class, IEntity { IUnitOfWork UnitOfWork { get; } #region Add - ValueTask AddAsync(TAggregateRoot entity, CancellationToken cancellationToken = default); + ValueTask AddAsync(TEntity entity, CancellationToken cancellationToken = default); - Task AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); + Task AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); #endregion #region Update - Task UpdateAsync(TAggregateRoot entity, CancellationToken cancellationToken = default); + Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default); - Task UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); + Task UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); #endregion #region Remove - Task RemoveAsync(TAggregateRoot entity, CancellationToken cancellationToken = default); + Task RemoveAsync(TEntity entity, CancellationToken cancellationToken = default); - Task RemoveRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); + Task RemoveRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default); - Task RemoveAsync(Expression> predicate, CancellationToken cancellationToken = default); + Task RemoveAsync(Expression> predicate, CancellationToken cancellationToken = default); #endregion #region Find - Task FindAsync(IEnumerable> keyValues, CancellationToken cancellationToken = default); + Task FindAsync(IEnumerable> keyValues, CancellationToken cancellationToken = default); - Task FindAsync(Expression> predicate, CancellationToken cancellationToken = default); + Task FindAsync(Expression> predicate, CancellationToken cancellationToken = default); #endregion #region Get - Task> GetListAsync(CancellationToken cancellationToken = default); + Task> GetListAsync(CancellationToken cancellationToken = default); - Task> GetListAsync(Expression> predicate, CancellationToken cancellationToken = default); + Task> GetListAsync(Expression> predicate, CancellationToken cancellationToken = default); Task GetCountAsync(CancellationToken cancellationToken = default); - Task GetCountAsync(Expression> predicate, CancellationToken cancellationToken = default); + Task GetCountAsync(Expression> predicate, CancellationToken cancellationToken = default); - Task> GetPaginatedListAsync(int skip, int take, Dictionary? sorting, CancellationToken cancellationToken = default); + Task> GetPaginatedListAsync(int skip, int take, Dictionary? sorting, + CancellationToken cancellationToken = default); - Task> GetPaginatedListAsync(Expression> predicate, int skip, int take, Dictionary? sorting, CancellationToken cancellationToken = default); + Task> GetPaginatedListAsync(Expression> predicate, int skip, int take, + Dictionary? sorting, CancellationToken cancellationToken = default); - Task> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default); + Task> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default); - Task> GetPaginatedListAsync(Expression> predicate, PaginatedOptions options, CancellationToken cancellationToken = default); + Task> GetPaginatedListAsync(Expression> predicate, PaginatedOptions options, + CancellationToken cancellationToken = default); #endregion + } -public interface IRepository : IRepository - where TAggregateRoot : class, IAggregateRoot +public interface IRepository : IRepository + where TEntity : class, IEntity where TKey : IComparable { #region Find - Task FindAsync(TKey id); + Task FindAsync(TKey id); #endregion }