Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
refactor: Repository removes AggregateRoot limit (#22)
Browse files Browse the repository at this point in the history
* 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 <wangzhenlei@gmail.com>

* 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 <wangzhenlei@gmail.com>

* 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 <wangzhenlei@gmail.com>

* 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 <wangzhenlei@gmail.com>

* 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 <wangzhenlei@gmail.com>

* 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 <wangzhenlei@gmail.com>

* 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 <wangzhenlei@gmail.com>
Co-authored-by: zhenlei520 <wangzhenlei@masastack.com>
Co-authored-by: unknown <louzhijian@lonsid.cn>
Co-authored-by: zhenlei520 <wangzhenlei520@gmail.com>
Co-authored-by: 王达 <wangda@lonsid.cn>
Co-authored-by: PollosD <55781685+PollosD@users.noreply.github.com>

Co-authored-by: 谷首道 <gushoudao@masastack.com>
Co-authored-by: zhenlei520 <wangzhenlei@gmail.com>
Co-authored-by: zhenlei520 <wangzhenlei@masastack.com>
Co-authored-by: unknown <louzhijian@lonsid.cn>
Co-authored-by: zhenlei520 <wangzhenlei520@gmail.com>
Co-authored-by: 王达 <wangda@lonsid.cn>
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 <wangzhenlei@gmail.com>
Co-authored-by: zhenlei520 <wangzhenlei@masastack.com>
Co-authored-by: unknown <louzhijian@lonsid.cn>
Co-authored-by: 王达 <wangda@lonsid.cn>
Co-authored-by: PollosD <55781685+PollosD@users.noreply.github.com>
Co-authored-by: 谷首道 <gushoudao@masastack.com>
  • Loading branch information
8 people authored Mar 8, 2022
1 parent ce0eb24 commit 11c5440
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
namespace Masa.BuildingBlocks.Ddd.Domain.Repositories;
public abstract class BaseRepository<TAggregateRoot> :
IRepository<TAggregateRoot>, IUnitOfWork
where TAggregateRoot : class, IAggregateRoot
public abstract class BaseRepository<TEntity> :
IRepository<TEntity>, IUnitOfWork
where TEntity : class, IEntity
{
#region IRepository<TEntity>

public abstract ValueTask<TAggregateRoot> AddAsync(TAggregateRoot entity, CancellationToken cancellationToken = default);
public abstract ValueTask<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default);

public virtual async Task AddRangeAsync(IEnumerable<TAggregateRoot> entities, CancellationToken cancellationToken = default)
public virtual async Task AddRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
{
foreach (var entity in entities)
{
await AddAsync(entity, cancellationToken);
}
}

public abstract Task<TAggregateRoot?> FindAsync(IEnumerable<KeyValuePair<string, object>> keyValues, CancellationToken cancellationToken = default);
public abstract Task<TEntity?> FindAsync(IEnumerable<KeyValuePair<string, object>> keyValues, CancellationToken cancellationToken = default);

public abstract Task<TAggregateRoot?> FindAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
public abstract Task<TEntity?> FindAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

public abstract Task<TAggregateRoot> RemoveAsync(TAggregateRoot entity, CancellationToken cancellationToken = default);
public abstract Task<TEntity> RemoveAsync(TEntity entity, CancellationToken cancellationToken = default);

public abstract Task RemoveAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
public abstract Task RemoveAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

public virtual async Task RemoveRangeAsync(IEnumerable<TAggregateRoot> entities, CancellationToken cancellationToken = default)
public virtual async Task RemoveRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
{
foreach (var entity in entities)
{
await RemoveAsync(entity, cancellationToken);
}
}

public abstract Task<TAggregateRoot> UpdateAsync(TAggregateRoot entity, CancellationToken cancellationToken = default);
public abstract Task<TEntity> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);

public virtual async Task UpdateRangeAsync(IEnumerable<TAggregateRoot> entities, CancellationToken cancellationToken = default)
public virtual async Task UpdateRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
{
foreach (var entity in entities)
{
await UpdateAsync(entity, cancellationToken);
}
}

public abstract Task<IEnumerable<TAggregateRoot>> GetListAsync(CancellationToken cancellationToken = default);
public abstract Task<IEnumerable<TEntity>> GetListAsync(CancellationToken cancellationToken = default);

public abstract Task<IEnumerable<TAggregateRoot>> GetListAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
public abstract Task<IEnumerable<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

public abstract Task<long> GetCountAsync(CancellationToken cancellationToken = default);

public abstract Task<long> GetCountAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
public abstract Task<long> GetCountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

public abstract Task<List<TAggregateRoot>> GetPaginatedListAsync(int skip, int take, Dictionary<string, bool>? sorting, CancellationToken cancellationToken = default);
public abstract Task<List<TEntity>> GetPaginatedListAsync(int skip, int take, Dictionary<string, bool>? sorting, CancellationToken cancellationToken = default);

public abstract Task<List<TAggregateRoot>> GetPaginatedListAsync(Expression<Func<TAggregateRoot, bool>> predicate, int skip, int take, Dictionary<string, bool>? sorting, CancellationToken cancellationToken = default);
public abstract Task<List<TEntity>> GetPaginatedListAsync(Expression<Func<TEntity, bool>> predicate, int skip, int take, Dictionary<string, bool>? sorting, CancellationToken cancellationToken = default);

public virtual async Task<PaginatedList<TAggregateRoot>> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default)
public virtual async Task<PaginatedList<TEntity>> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default)
{
var result = await GetPaginatedListAsync(
(options.Page - 1) * options.PageSize,
Expand All @@ -64,15 +64,15 @@ public virtual async Task<PaginatedList<TAggregateRoot>> GetPaginatedListAsync(P

var total = await GetCountAsync(cancellationToken);

return new PaginatedList<TAggregateRoot>()
return new PaginatedList<TEntity>()
{
Total = total,
Result = result,
TotalPages = (int)Math.Ceiling(total / (decimal)options.PageSize)
};
}

public async Task<PaginatedList<TAggregateRoot>> GetPaginatedListAsync(Expression<Func<TAggregateRoot, bool>> predicate, PaginatedOptions options, CancellationToken cancellationToken = default)
public async Task<PaginatedList<TEntity>> GetPaginatedListAsync(Expression<Func<TEntity, bool>> predicate, PaginatedOptions options, CancellationToken cancellationToken = default)
{
var result = await GetPaginatedListAsync(
predicate,
Expand All @@ -84,7 +84,7 @@ public async Task<PaginatedList<TAggregateRoot>> GetPaginatedListAsync(Expressio

var total = await GetCountAsync(predicate, cancellationToken);

return new PaginatedList<TAggregateRoot>()
return new PaginatedList<TEntity>()
{
Total = total,
Result = result,
Expand Down
46 changes: 25 additions & 21 deletions src/Ddd/Masa.BuildingBlocks.Ddd.Domain/Repositories/IRepository.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
namespace Masa.BuildingBlocks.Ddd.Domain.Repositories;
public interface IRepository<TAggregateRoot>
where TAggregateRoot : class, IAggregateRoot
public interface IRepository<TEntity>
where TEntity : class, IEntity
{
IUnitOfWork UnitOfWork { get; }

#region Add

ValueTask<TAggregateRoot> AddAsync(TAggregateRoot entity, CancellationToken cancellationToken = default);
ValueTask<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default);

Task AddRangeAsync(IEnumerable<TAggregateRoot> entities, CancellationToken cancellationToken = default);
Task AddRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);

#endregion

#region Update

Task<TAggregateRoot> UpdateAsync(TAggregateRoot entity, CancellationToken cancellationToken = default);
Task<TEntity> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);

Task UpdateRangeAsync(IEnumerable<TAggregateRoot> entities, CancellationToken cancellationToken = default);
Task UpdateRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);

#endregion

#region Remove

Task<TAggregateRoot> RemoveAsync(TAggregateRoot entity, CancellationToken cancellationToken = default);
Task<TEntity> RemoveAsync(TEntity entity, CancellationToken cancellationToken = default);

Task RemoveRangeAsync(IEnumerable<TAggregateRoot> entities, CancellationToken cancellationToken = default);
Task RemoveRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);

Task RemoveAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
Task RemoveAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

#endregion

#region Find

Task<TAggregateRoot?> FindAsync(IEnumerable<KeyValuePair<string, object>> keyValues, CancellationToken cancellationToken = default);
Task<TEntity?> FindAsync(IEnumerable<KeyValuePair<string, object>> keyValues, CancellationToken cancellationToken = default);

Task<TAggregateRoot?> FindAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
Task<TEntity?> FindAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

#endregion

#region Get

Task<IEnumerable<TAggregateRoot>> GetListAsync(CancellationToken cancellationToken = default);
Task<IEnumerable<TEntity>> GetListAsync(CancellationToken cancellationToken = default);

Task<IEnumerable<TAggregateRoot>> GetListAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
Task<IEnumerable<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

Task<long> GetCountAsync(CancellationToken cancellationToken = default);

Task<long> GetCountAsync(Expression<Func<TAggregateRoot, bool>> predicate, CancellationToken cancellationToken = default);
Task<long> GetCountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);

Task<List<TAggregateRoot>> GetPaginatedListAsync(int skip, int take, Dictionary<string, bool>? sorting, CancellationToken cancellationToken = default);
Task<List<TEntity>> GetPaginatedListAsync(int skip, int take, Dictionary<string, bool>? sorting,
CancellationToken cancellationToken = default);

Task<List<TAggregateRoot>> GetPaginatedListAsync(Expression<Func<TAggregateRoot, bool>> predicate, int skip, int take, Dictionary<string, bool>? sorting, CancellationToken cancellationToken = default);
Task<List<TEntity>> GetPaginatedListAsync(Expression<Func<TEntity, bool>> predicate, int skip, int take,
Dictionary<string, bool>? sorting, CancellationToken cancellationToken = default);

Task<PaginatedList<TAggregateRoot>> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default);
Task<PaginatedList<TEntity>> GetPaginatedListAsync(PaginatedOptions options, CancellationToken cancellationToken = default);

Task<PaginatedList<TAggregateRoot>> GetPaginatedListAsync(Expression<Func<TAggregateRoot, bool>> predicate, PaginatedOptions options, CancellationToken cancellationToken = default);
Task<PaginatedList<TEntity>> GetPaginatedListAsync(Expression<Func<TEntity, bool>> predicate, PaginatedOptions options,
CancellationToken cancellationToken = default);

#endregion

}

public interface IRepository<TAggregateRoot, TKey> : IRepository<TAggregateRoot>
where TAggregateRoot : class, IAggregateRoot<TKey>
public interface IRepository<TEntity, TKey> : IRepository<TEntity>
where TEntity : class, IEntity<TKey>
where TKey : IComparable
{
#region Find

Task<TAggregateRoot?> FindAsync(TKey id);
Task<TEntity?> FindAsync(TKey id);

#endregion
}

0 comments on commit 11c5440

Please sign in to comment.