From 5bd4c78bd81a85ce8f2a0abc1f29504ea8899bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 25 Jan 2018 11:00:03 +0300 Subject: [PATCH] Enabled entity, repo and aggr root without pk. --- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 13824 -> 13824 bytes .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 13 +-- .../Volo/Abp/Domain/Entities/Entity.cs | 27 +++--- .../Abp/Domain/Entities/IAggregateRoot.cs | 20 ++-- .../Volo/Abp/Domain/Entities/IEntity.cs | 21 ++--- .../Repositories/IQueryableRepository.cs | 15 ++- .../Abp/Domain/Repositories/IRepository.cs | 87 +++++++++--------- .../Repositories/QueryableRepositoryBase.cs | 84 ++++++++++++----- .../Abp/Domain/Repositories/RepositoryBase.cs | 86 ++++++----------- .../EntityFrameworkCore/EfCoreRepository.cs | 22 ++--- .../Identity/EfCoreIdentityRoleRepository.cs | 5 + .../Identity/EfCoreIdentityUserRepository.cs | 5 + .../Repositories/MongoDB/MongoDbRepository.cs | 12 --- .../CancellationTokenProviderExtensions.cs | 2 +- .../RepositoryRegistration_Tests.cs | 10 -- 15 files changed, 201 insertions(+), 208 deletions(-) diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index b1659c1e3458fd38570b90275dad352539769fea..e75d37d1ba920d4860c758db227497eab4ed1c25 100644 GIT binary patch delta 1158 zcmZXSU2GI(6o%jPO=tFJw%hHpMUrWgEeole!iLJm6d?)$jI|iB5`RLhH4D*IpepNy zQM21DkP;i(yCS7!Q`3?|`>p%TFYR}=kWg%sqx1#t&X9Gv_3)SO=)ka*k;b0)42xAmy zCX~m3N-`%U`9b&x-NVV-tnbBD+@}`u-R@^D!9!{b-y7J!DDUs$p6&Avl~A`*7!Ws! z@BA5dzg69@RyM2*+!k9xn0obK(4klL$3dsHpiE3J2CvD$X;mf@H^fZ@rc?wb=Bl-s zP+89fow~ishhW0%p9p+oAJmTRv>s7@ye!#%T;g3e`o&FRnN_9`PS3kQ(kSa^ZHLPG zP1|W2QDMwhCyn`zvAb36ds3D42|L;J8P958B4?9HF?=tsv}m8dpzqjDT}8!kN3tT8 z<4bpGC_}zYv<5lK=)u~ie2&&p-v0(4BJa1*tPWU3ieVRJXoDm%8Jtv8q4$W?b^AlE zdYx%}YM!DrJ~GFtO?i(&>Swz`^*qhOD%BmBq9mQNzorhgkFHP{e%zucI#92oc!Zha z*Kj@0mj$@VbPzUDNZ>AJt8gWnSg#hnUf78=Cy$|8Ifc}l8Wex==_YB88N?zCh|5Dd7GO>H;Y~?dR>)XwMTS8I4nFP zoSx5>H)mLQMmQ}5A8FKx3)emk^l-|dv+j7Ri%KhM S-0+IO40UadTc5tk-uDlj&Is24 delta 1161 zcmZXSeP~-%7{;IX+}@kq+%!$obaY&cNz+kEyRdF$cC27WHzC$JnKB(R&FF%bZmZjZ zQbg0Pwrn`IWk(!CBC8IEC}wb-8;*>Xjf9GS*nKfkSgW{o;8zrMYzm(HHvS==KYsUl zp7%ZPJ@;c|`^fgg`>LjP50|qC9-v#<51%F}iCXmeKA=mMmwbmp$aL`;L2zhE! zj0u;fXj3e5@-6ds>Qu?wO0UFs=oX9A-Fg(8@u+x0-5Z!_$atSpJ=+!>ru<1EaDZJA zH@qq3eyX@1jKP4=aF=Zs0oo-G`D}Vce&n;;_6i-dO;D?77DSG8%(J^>mP8Ob%9Yxj zKPSsRyJkXo;ETEam(0u7VQE`-+dIOGU7Sr|M(wh&k6jV%MvnX_EI6}O%gL>lO*#3R zWjDSr0=Qk7l=pnB+^?0sXGBh(wptrMQ?t67`D{EXjBnUw8^*nR<$cSpxhTT8&)FE3 z;tOYqzn?shQ#aC-l834rGcVH`%6MN_hsbyhM8$q%oWj^aDO$@(mWNVRI3fmPx;bDCP|to0Qo#5i520KE8(LP(%ags@&Q zu3p1@MqTPqR9#ncY>t1FbR;uJlBo&{ z3(VPtT)1K6=`j_0Q0i(*C&)jY3nqAhepUa5)I&(bQD0}NNFbw^sk{`x!gm(O+ot&9aXsLBcR z|CQUpEp$+>t37S6+nF9n4<|d2*qL6j9EpvomxlHXq=$A7C!PAx!@=NNi_bjN{O)_b zNA0h_{G$+(&bFqt, IAggregateRoot - //{ - //} + /// + public abstract class AggregateRoot : IAggregateRoot + { + + } + /// public abstract class AggregateRoot : Entity, IAggregateRoot { diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs index 6cc3303565..2ad2664f7d 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs @@ -1,23 +1,15 @@ -using System; -using System.Reflection; +using System.Reflection; namespace Volo.Abp.Domain.Entities { - ///// - ///// A shortcut of for default primary key type (). - ///// - //public abstract class Entity : Entity, IEntity - //{ + /// + public abstract class Entity : IEntity + { - //} + } - /// - /// - /// Basic implementation of IEntity interface. - /// An entity can inherit this class of directly implement to IEntity interface. - /// - /// Type of the primary key of the entity - public abstract class Entity : IEntity + /// + public abstract class Entity : Entity, IEntity { /// public virtual TPrimaryKey Id { get; set; } @@ -57,6 +49,11 @@ namespace Volo.Abp.Domain.Entities /// public override int GetHashCode() { + if (Id == null) + { + return 0; + } + return Id.GetHashCode(); } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs index adb3f11d60..51d51a9677 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IAggregateRoot.cs @@ -1,13 +1,19 @@ -using System; - -namespace Volo.Abp.Domain.Entities +namespace Volo.Abp.Domain.Entities { - //public interface IAggregateRoot : IAggregateRoot, IEntity - //{ + /// + /// Defines an aggregate root. It's primary key may not be "Id" or it may have a composite primary key. + /// Use where possible for better integration to repositories and other structures in the framework. + /// + public interface IAggregateRoot : IEntity + { - //} + } - public interface IAggregateRoot : IEntity + /// + /// Defines an aggregate root with a single primary key with "Id" property. + /// + /// Type of the primary key of the entity + public interface IAggregateRoot : IAggregateRoot, IEntity { } diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs index ff798a8253..a2f17e3f82 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs @@ -1,20 +1,19 @@ -using System; - -namespace Volo.Abp.Domain.Entities +namespace Volo.Abp.Domain.Entities { - ///// - ///// A shortcut of for default primary key type (). - ///// - //public interface IEntity : IEntity - //{ + /// + /// Defines an entity. It's primary key may not be "Id" or it mah have a composite primary key. + /// Use where possible for better integration to repositories and other structures in the framework. + /// + public interface IEntity + { - //} + } /// - /// Defines interface for base entity type. All entities in the system must implement this interface. + /// Defines an entity with a single primary key with "Id" property. /// /// Type of the primary key of the entity - public interface IEntity + public interface IEntity : IEntity { /// /// Unique identifier for this entity. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs index 08bb61a442..6a0e35e4ed 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IQueryableRepository.cs @@ -8,14 +8,8 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories { - //public interface IQueryableRepository : IQueryableRepository, IRepository - // where TEntity : class, IEntity - //{ - - //} - - public interface IQueryableRepository : IRepository, IQueryable - where TEntity : class, IEntity + public interface IQueryableRepository : IRepository, IQueryable + where TEntity : class, IEntity { /// /// Deletes many entities by function. @@ -36,4 +30,9 @@ namespace Volo.Abp.Domain.Repositories /// A condition to filter entities Task DeleteAsync([NotNull] Expression> predicate, CancellationToken cancellationToken = default); } + + public interface IQueryableRepository : IQueryableRepository, IRepository + where TEntity : class, IEntity + { + } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs index 31dfd82682..1b70ff510f 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs @@ -6,55 +6,17 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories { + /// + /// Just to mark a class as repository. + /// public interface IRepository : ITransientDependency { } - //public interface IRepository : IRepository - // where TEntity : class, IEntity - //{ - - //} - - public interface IRepository : IRepository - where TEntity : class, IEntity + public interface IRepository : IRepository + where TEntity : class, IEntity { - /// - /// Gets an entity with given primary key. - /// Throws if can not find an entity with given id. - /// - /// Primary key of the entity to get - /// Entity - [NotNull] - TEntity Get(TPrimaryKey id); - - /// - /// Gets an entity with given primary key. - /// Throws if can not find an entity with given id. - /// - /// Primary key of the entity to get - /// A to observe while waiting for the task to complete. - /// Entity - [NotNull] - Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default); - - /// - /// Gets an entity with given primary key or null if not found. - /// - /// Primary key of the entity to get - /// Entity or null - [CanBeNull] - TEntity Find(TPrimaryKey id); //TODO: Rename to FirstOrDefault..? - - /// - /// Gets an entity with given primary key or null if not found. - /// - /// Primary key of the entity to get - /// A to observe while waiting for the task to complete. - /// Entity or null - Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default); - /// /// Inserts a new entity. /// @@ -105,6 +67,45 @@ namespace Volo.Abp.Domain.Repositories /// A to observe while waiting for the task to complete. /// Entity to be deleted Task DeleteAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default); //TODO: Return true if deleted + } + + public interface IRepository : IRepository + where TEntity : class, IEntity + { + /// + /// Gets an entity with given primary key. + /// Throws if can not find an entity with given id. + /// + /// Primary key of the entity to get + /// Entity + [NotNull] + TEntity Get(TPrimaryKey id); + + /// + /// Gets an entity with given primary key. + /// Throws if can not find an entity with given id. + /// + /// Primary key of the entity to get + /// A to observe while waiting for the task to complete. + /// Entity + [NotNull] + Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default); + + /// + /// Gets an entity with given primary key or null if not found. + /// + /// Primary key of the entity to get + /// Entity or null + [CanBeNull] + TEntity Find(TPrimaryKey id); + + /// + /// Gets an entity with given primary key or null if not found. + /// + /// Primary key of the entity to get + /// A to observe while waiting for the task to complete. + /// Entity or null + Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default); /// /// Deletes an entity by primary key. diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs index 8bdc50b4b3..c3f67b0b33 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/QueryableRepositoryBase.cs @@ -11,14 +11,8 @@ using Volo.Abp.MultiTenancy; namespace Volo.Abp.Domain.Repositories { - //public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository - // where TEntity : class, IEntity - //{ - - //} - - public abstract class QueryableRepositoryBase : RepositoryBase, IQueryableRepository - where TEntity : class, IEntity + public abstract class QueryableRepositoryBase : RepositoryBase, IQueryableRepository + where TEntity : class, IEntity { public virtual Type ElementType => GetQueryable().ElementType; @@ -26,10 +20,6 @@ namespace Volo.Abp.Domain.Repositories public virtual IQueryProvider Provider => GetQueryable().Provider; - public IDataFilter DataFilter { get; set; } - - public ICurrentTenant CurrentTenant { get; set; } - IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); @@ -42,33 +32,70 @@ namespace Volo.Abp.Domain.Repositories protected abstract IQueryable GetQueryable(); - public override List GetList() + public virtual void Delete(Expression> predicate) { - return GetQueryable().ToList(); + foreach (var entity in GetQueryable().Where(predicate).ToList()) + { + Delete(entity); + } } - public override TEntity Find(TPrimaryKey id) + public virtual Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) + { + Delete(predicate); + return Task.CompletedTask; + } + } + + public abstract class QueryableRepositoryBase : QueryableRepositoryBase, IQueryableRepository + where TEntity : class, IEntity + { + public IDataFilter DataFilter { get; set; } + + public ICurrentTenant CurrentTenant { get; set; } + + public virtual TEntity Find(TPrimaryKey id) { return GetQueryable().FirstOrDefault(CreateEqualityExpressionForId(id)); } - public virtual void Delete(Expression> predicate) + public virtual TEntity Get(TPrimaryKey id) { - foreach (var entity in GetQueryable().Where(predicate).ToList()) + var entity = Find(id); + + if (entity == null) { - Delete(entity); + throw new EntityNotFoundException(typeof(TEntity), id); } + + return entity; } - public virtual Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) + public virtual Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - Delete(predicate); - return Task.CompletedTask; + return Task.FromResult(Get(id)); } - public override long GetCount() + public virtual Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - return GetQueryable().LongCount(); + return Task.FromResult(Find(id)); + } + + public virtual void Delete(TPrimaryKey id) + { + var entity = Find(id); + if (entity == null) + { + return; + } + + Delete(entity); + } + + public virtual Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) + { + Delete(id); + return Task.CompletedTask; } protected virtual IQueryable ApplyDataFilters(IQueryable query) @@ -86,5 +113,16 @@ namespace Volo.Abp.Domain.Repositories return query; } + + protected static Expression> CreateEqualityExpressionForId(TPrimaryKey id) + { + var lambdaParam = Expression.Parameter(typeof(TEntity)); + var lambdaBody = Expression.Equal( + Expression.PropertyOrField(lambdaParam, "Id"), + Expression.Constant(id, typeof(TPrimaryKey)) + ); + + return Expression.Lambda>(lambdaBody, lambdaParam); + } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs index a1c890c600..bc52a145a8 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs @@ -1,21 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Entities; using Volo.Abp.Threading; namespace Volo.Abp.Domain.Repositories { - //public abstract class RepositoryBase : RepositoryBase, IRepository - // where TEntity : class, IEntity - //{ - - //} - - public abstract class RepositoryBase : IRepository - where TEntity : class, IEntity + public abstract class RepositoryBase : IRepository + where TEntity : class, IEntity { public ICancellationTokenProvider CancellationTokenProvider { get; set; } @@ -24,13 +15,37 @@ namespace Volo.Abp.Domain.Repositories CancellationTokenProvider = NullCancellationTokenProvider.Instance; } - public abstract List GetList(); + public abstract TEntity Insert(TEntity entity, bool autoSave = false); - public virtual Task> GetListAsync(CancellationToken cancellationToken = default) + public virtual Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) { - return Task.FromResult(GetList()); + return Task.FromResult(Insert(entity, autoSave)); } + public abstract TEntity Update(TEntity entity); + + public virtual Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) + { + return Task.FromResult(Update(entity)); + } + + public abstract void Delete(TEntity entity); + + public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) + { + Delete(entity); + return Task.CompletedTask; + } + + protected virtual CancellationToken GetCancellationToken(CancellationToken prefferedValue = default) + { + return CancellationTokenProvider.FallbackToProvider(prefferedValue); + } + } + + public abstract class RepositoryBase : RepositoryBase, IRepository + where TEntity : class, IEntity + { public virtual TEntity Get(TPrimaryKey id) { var entity = Find(id); @@ -55,28 +70,6 @@ namespace Volo.Abp.Domain.Repositories return Task.FromResult(Find(id)); } - public abstract TEntity Insert(TEntity entity, bool autoSave = false); - - public virtual Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) - { - return Task.FromResult(Insert(entity, autoSave)); - } - - public abstract TEntity Update(TEntity entity); - - public virtual Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) - { - return Task.FromResult(Update(entity)); - } - - public abstract void Delete(TEntity entity); - - public virtual Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default) - { - Delete(entity); - return Task.CompletedTask; - } - public virtual void Delete(TPrimaryKey id) { var entity = Find(id); @@ -93,24 +86,5 @@ namespace Volo.Abp.Domain.Repositories Delete(id); return Task.CompletedTask; } - - public abstract long GetCount(); - - public virtual Task GetCountAsync(CancellationToken cancellationToken = default) - { - return Task.FromResult(GetCount()); - } - - protected static Expression> CreateEqualityExpressionForId(TPrimaryKey id) - { - var lambdaParam = Expression.Parameter(typeof(TEntity)); - - var lambdaBody = Expression.Equal( - Expression.PropertyOrField(lambdaParam, "Id"), - Expression.Constant(id, typeof(TPrimaryKey)) - ); - - return Expression.Lambda>(lambdaBody, lambdaParam); - } } } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 07047bd69b..698df13738 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -46,14 +46,9 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore return DbSet.AsQueryable(); } - public override Task> GetListAsync(CancellationToken cancellationToken = default) - { - return DbSet.ToListAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); - } - public override async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - var entity = await FindAsync(id, CancellationTokenProvider.FallbackToProvider(cancellationToken)); + var entity = await FindAsync(id, GetCancellationToken(cancellationToken)); if (entity == null) { @@ -70,7 +65,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore public override Task FindAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { - return DbSet.FindAsync(new object[] { id }, CancellationTokenProvider.FallbackToProvider(cancellationToken)); + return DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken)); } public override TEntity Insert(TEntity entity, bool autoSave = false) @@ -91,7 +86,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore if (autoSave) { - await DbContext.SaveChangesAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + await DbContext.SaveChangesAsync(GetCancellationToken(cancellationToken)); } return savedEntity; @@ -110,25 +105,20 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore public override async Task DeleteAsync(Expression> predicate, CancellationToken cancellationToken = default) { - var entities = await GetQueryable().Where(predicate).ToListAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + var entities = await GetQueryable().Where(predicate).ToListAsync(GetCancellationToken(cancellationToken)); foreach (var entity in entities) { DbSet.Remove(entity); } } - public override Task GetCountAsync(CancellationToken cancellationToken = default) - { - return GetQueryable().LongCountAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); - } - public virtual Task EnsureCollectionLoadedAsync( TEntity entity, Expression>> propertyExpression, CancellationToken cancellationToken = default) where TProperty : class { - return DbContext.Entry(entity).Collection(propertyExpression).LoadAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + return DbContext.Entry(entity).Collection(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); } public virtual Task EnsurePropertyLoadedAsync( @@ -137,7 +127,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore CancellationToken cancellationToken = default) where TProperty : class { - return DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken)); + return DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); } } } diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs index 8788cdf3dc..864db178e0 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs @@ -30,5 +30,10 @@ namespace Volo.Abp.Identity .PageBy(skipCount, maxResultCount) .ToListAsync(); } + + public async Task GetCountAsync(CancellationToken cancellationToken = default) + { + return await this.LongCountAsync(cancellationToken); + } } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs index 834b663072..a9e4c553df 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs @@ -107,5 +107,10 @@ namespace Volo.Abp.Identity return await query.ToListAsync(); } + + public async Task GetCountAsync(CancellationToken cancellationToken = default) + { + return await this.LongCountAsync(cancellationToken); + } } } diff --git a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 7ad3f6c29a..2465246e61 100644 --- a/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -37,13 +37,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB DatabaseProvider = databaseProvider; } - //TODO: Override other methods? - - public override async Task> GetListAsync(CancellationToken cancellationToken = new CancellationToken()) - { - return await (await Collection.FindAsync(Builders.Filter.Empty, cancellationToken: cancellationToken)).ToListAsync(cancellationToken); - } - public override async Task GetAsync(TPrimaryKey id, CancellationToken cancellationToken = default) { var entity = await FindAsync(id, cancellationToken); @@ -120,10 +113,5 @@ namespace Volo.Abp.Domain.Repositories.MongoDB { return Collection.AsQueryable(); } - - public override Task GetCountAsync(CancellationToken cancellationToken = default) - { - return Collection.CountAsync(Builders.Filter.Empty, cancellationToken: cancellationToken); - } } } \ No newline at end of file diff --git a/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs b/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs index 0f84c725c5..b1ad755db2 100644 --- a/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs +++ b/src/Volo.Abp.Threading/Volo/Abp/Threading/CancellationTokenProviderExtensions.cs @@ -4,7 +4,7 @@ namespace Volo.Abp.Threading { public static class CancellationTokenProviderExtensions { - public static CancellationToken FallbackToProvider(this ICancellationTokenProvider provider, CancellationToken prefferedValue) + public static CancellationToken FallbackToProvider(this ICancellationTokenProvider provider, CancellationToken prefferedValue = default) { return prefferedValue == default ? provider.Token : prefferedValue; } diff --git a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index c9ba7b5b29..f5554f00b0 100644 --- a/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -164,16 +164,6 @@ namespace Volo.Abp.Domain.Repositories { throw new NotImplementedException(); } - - public override long GetCount() - { - throw new NotImplementedException(); - } - - public override List GetList() - { - throw new NotImplementedException(); - } } public class MyTestAggregateRootWithDefaultPkCustomRepository : MyTestDefaultRepository