Browse Source

Example implementation for the repository async extensions.

pull/5477/head
Halil İbrahim Kalkan 6 years ago
parent
commit
37514cef5a
  1. 3
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs
  2. 41
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs
  3. 9
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs

3
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs

@ -2,12 +2,15 @@
using System.Linq;
using System.Linq.Expressions;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Linq;
namespace Volo.Abp.Domain.Repositories
{
public interface IReadOnlyRepository<TEntity> : IQueryable<TEntity>, IReadOnlyBasicRepository<TEntity>
where TEntity : class, IEntity
{
IAsyncQueryableExecuter AsyncExecuter { get; }
IQueryable<TEntity> WithDetails();
IQueryable<TEntity> WithDetails(params Expression<Func<TEntity, object>>[] propertySelectors);

41
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs

@ -0,0 +1,41 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public static class RepositoryAsyncExtensions
{
#region Count/LongCount
public static Task<int> CountAsync<T>(
[NotNull] this IReadOnlyRepository<T> repository,
CancellationToken cancellationToken = default)
where T : class, IEntity
{
return repository.AsyncExecuter.CountAsync(
repository,
cancellationToken
);
}
public static Task<int> CountAsync<T>(
[NotNull] this IReadOnlyRepository<T> repository,
[NotNull] Expression<Func<T, bool>> predicate,
CancellationToken cancellationToken = default)
where T : class, IEntity
{
return repository.AsyncExecuter.CountAsync(
repository,
predicate,
cancellationToken
);
}
#endregion
}
}

9
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs

@ -7,6 +7,7 @@ using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Linq;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
@ -19,6 +20,8 @@ namespace Volo.Abp.Domain.Repositories
public ICurrentTenant CurrentTenant { get; set; }
public IAsyncQueryableExecuter AsyncExecuter { get; set; }
public IUnitOfWorkManager UnitOfWorkManager { get; set; }
public virtual Type ElementType => GetQueryable().ElementType;
@ -50,12 +53,12 @@ namespace Volo.Abp.Domain.Repositories
protected abstract IQueryable<TEntity> GetQueryable();
public abstract Task<TEntity> FindAsync(
Expression<Func<TEntity, bool>> predicate,
Expression<Func<TEntity, bool>> predicate,
bool includeDetails = true,
CancellationToken cancellationToken = default);
public async Task<TEntity> GetAsync(
Expression<Func<TEntity, bool>> predicate,
Expression<Func<TEntity, bool>> predicate,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
@ -107,4 +110,4 @@ namespace Volo.Abp.Domain.Repositories
await DeleteAsync(entity, autoSave, cancellationToken);
}
}
}
}

Loading…
Cancel
Save