Browse Source

All repo methods should be virtual and use async if returns Task.

pull/206/head
Halil İbrahim Kalkan 8 years ago
parent
commit
eebd0e76b6
  1. 1
      src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs
  2. 14
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  3. 2
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  4. 8
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs
  5. 27
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs
  6. 2
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs
  7. 4
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs
  8. 8
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResourceRepository.cs
  9. 2
      src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
  10. 2
      src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  11. 10
      src/Volo.Abp.MultiTenancy.EntityFrameworkCore/Volo/Abp/MultiTenancy/EfCoreTenantRepository.cs

1
src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/RepositoryBase.cs

@ -50,7 +50,6 @@ namespace Volo.Abp.Domain.Repositories
return Task.CompletedTask; return Task.CompletedTask;
} }
//TODO: Is that needed..?
protected virtual IQueryable<TEntity> ApplyDataFilters(IQueryable<TEntity> query) protected virtual IQueryable<TEntity> ApplyDataFilters(IQueryable<TEntity> query)
{ {
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))

14
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -76,22 +76,22 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
} }
} }
public virtual Task EnsureCollectionLoadedAsync<TProperty>( public virtual async Task EnsureCollectionLoadedAsync<TProperty>(
TEntity entity, TEntity entity,
Expression<Func<TEntity, IEnumerable<TProperty>>> propertyExpression, Expression<Func<TEntity, IEnumerable<TProperty>>> propertyExpression,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
where TProperty : class where TProperty : class
{ {
return DbContext.Entry(entity).Collection(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); await DbContext.Entry(entity).Collection(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken));
} }
public virtual Task EnsurePropertyLoadedAsync<TProperty>( public virtual async Task EnsurePropertyLoadedAsync<TProperty>(
TEntity entity, TEntity entity,
Expression<Func<TEntity, TProperty>> propertyExpression, Expression<Func<TEntity, TProperty>> propertyExpression,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
where TProperty : class where TProperty : class
{ {
return DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); await DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken));
} }
} }
@ -108,7 +108,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
} }
public TEntity Get(TKey id) public virtual TEntity Get(TKey id)
{ {
var entity = Find(id); var entity = Find(id);
@ -137,9 +137,9 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return DbSet.Find(id); return DbSet.Find(id);
} }
public virtual Task<TEntity> FindAsync(TKey id, CancellationToken cancellationToken = default) public virtual async Task<TEntity> FindAsync(TKey id, CancellationToken cancellationToken = default)
{ {
return DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken)); return await DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken));
} }
public virtual void Delete(TKey id) public virtual void Delete(TKey id)

2
src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

@ -5,8 +5,6 @@ using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
//TODO: Consider a way of passing cancellation token to all async application service methods!
public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppService public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppService
{ {
private readonly IdentityUserManager _userManager; private readonly IdentityUserManager _userManager;

8
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs

@ -18,12 +18,12 @@ namespace Volo.Abp.Identity
{ {
} }
public Task<IdentityRole> FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken) public virtual async Task<IdentityRole> FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
{ {
return DbSet.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, cancellationToken); return await DbSet.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, cancellationToken);
} }
public async Task<List<IdentityRole>> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0) public virtual async Task<List<IdentityRole>> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0)
{ {
return await this return await this
.OrderBy(sorting ?? nameof(IdentityRole.Name)) .OrderBy(sorting ?? nameof(IdentityRole.Name))
@ -31,7 +31,7 @@ namespace Volo.Abp.Identity
.ToListAsync(); .ToListAsync();
} }
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{ {
return await this.LongCountAsync(cancellationToken); return await this.LongCountAsync(cancellationToken);
} }

27
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs

@ -19,24 +19,23 @@ namespace Volo.Abp.Identity
{ {
} }
public Task<IdentityUser> FindByNormalizedUserNameAsync(string normalizedUserName, CancellationToken cancellationToken) public virtual async Task<IdentityUser> FindByNormalizedUserNameAsync(string normalizedUserName, CancellationToken cancellationToken)
{ {
return DbSet.FirstOrDefaultAsync(u => u.NormalizedUserName == normalizedUserName, cancellationToken); return await DbSet.FirstOrDefaultAsync(u => u.NormalizedUserName == normalizedUserName, cancellationToken);
} }
public Task<List<string>> GetRoleNamesAsync(Guid userId) public virtual async Task<List<string>> GetRoleNamesAsync(Guid userId)
{ {
var query = from userRole in DbContext.UserRoles var query = from userRole in DbContext.UserRoles
join role in DbContext.Roles on userRole.RoleId equals role.Id join role in DbContext.Roles on userRole.RoleId equals role.Id
where userRole.UserId.Equals(userId) where userRole.UserId.Equals(userId)
select role.Name; select role.Name;
return query.ToListAsync(); return await query.ToListAsync();
} }
public async Task<IdentityUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken) public virtual async Task<IdentityUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)
{ {
//TODO: This should be changed since loginProvider, providerKey are not PKs.
var userLogin = await DbContext.UserLogins var userLogin = await DbContext.UserLogins
.Where(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey) .Where(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey)
.FirstOrDefaultAsync(cancellationToken); .FirstOrDefaultAsync(cancellationToken);
@ -49,12 +48,12 @@ namespace Volo.Abp.Identity
return await DbSet.FindAsync(new object[] { userLogin.UserId }, cancellationToken); return await DbSet.FindAsync(new object[] { userLogin.UserId }, cancellationToken);
} }
public Task<IdentityUser> FindByNormalizedEmailAsync(string normalizedEmail, CancellationToken cancellationToken) public virtual async Task<IdentityUser> FindByNormalizedEmailAsync(string normalizedEmail, CancellationToken cancellationToken)
{ {
return DbSet.FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, cancellationToken); return await DbSet.FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, cancellationToken);
} }
public async Task<IList<IdentityUser>> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken) public virtual async Task<IList<IdentityUser>> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken)
{ {
var query = from userclaims in DbContext.UserClaims var query = from userclaims in DbContext.UserClaims
join user in DbContext.Users on userclaims.UserId equals user.Id join user in DbContext.Users on userclaims.UserId equals user.Id
@ -64,7 +63,7 @@ namespace Volo.Abp.Identity
return await query.ToListAsync(cancellationToken); return await query.ToListAsync(cancellationToken);
} }
public async Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken) public virtual async Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
{ {
var role = await DbContext.Roles.Where(x => x.NormalizedName == normalizedRoleName).FirstOrDefaultAsync(cancellationToken); var role = await DbContext.Roles.Where(x => x.NormalizedName == normalizedRoleName).FirstOrDefaultAsync(cancellationToken);
@ -81,7 +80,7 @@ namespace Volo.Abp.Identity
return await query.ToListAsync(cancellationToken); return await query.ToListAsync(cancellationToken);
} }
public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default) public virtual async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default)
{ {
return await this.WhereIf( return await this.WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
@ -94,12 +93,12 @@ namespace Volo.Abp.Identity
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount) public virtual async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{ {
return await this.OrderBy(sorting ?? nameof(IdentityUser.UserName)).PageBy(skipCount, maxResultCount).ToListAsync(); return await this.OrderBy(sorting ?? nameof(IdentityUser.UserName)).PageBy(skipCount, maxResultCount).ToListAsync();
} }
public async Task<List<IdentityRole>> GetRolesAsync(Guid userId) public virtual async Task<List<IdentityRole>> GetRolesAsync(Guid userId)
{ {
var query = from userRole in DbContext.UserRoles var query = from userRole in DbContext.UserRoles
join role in DbContext.Roles on userRole.RoleId equals role.Id join role in DbContext.Roles on userRole.RoleId equals role.Id
@ -109,7 +108,7 @@ namespace Volo.Abp.Identity
return await query.ToListAsync(); return await query.ToListAsync();
} }
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{ {
return await this.LongCountAsync(cancellationToken); return await this.LongCountAsync(cancellationToken);
} }

2
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs

@ -16,7 +16,7 @@ namespace Volo.Abp.IdentityServer
} }
public async Task<ApiResource> FindByNameAsync(string name, CancellationToken cancellationToken = default) public virtual async Task<ApiResource> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{ {
return await this.FirstOrDefaultAsync(ar => ar.Name == name, cancellationToken); return await this.FirstOrDefaultAsync(ar => ar.Name == name, cancellationToken);
} }

4
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs

@ -15,9 +15,9 @@ namespace Volo.Abp.IdentityServer
} }
public Task<Client> FindByCliendIdIncludingAllAsync(string clientId) public virtual async Task<Client> FindByCliendIdIncludingAllAsync(string clientId)
{ {
return DbSet return await DbSet
.Include(x => x.AllowedGrantTypes) .Include(x => x.AllowedGrantTypes)
.Include(x => x.RedirectUris) .Include(x => x.RedirectUris)
.Include(x => x.PostLogoutRedirectUris) .Include(x => x.PostLogoutRedirectUris)

8
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResourceRepository.cs

@ -22,7 +22,7 @@ namespace Volo.Abp.IdentityServer
} }
public async Task<List<IdentityResource>> FindIdentityResourcesByScopeAsync(string[] scopeNames) public virtual async Task<List<IdentityResource>> FindIdentityResourcesByScopeAsync(string[] scopeNames)
{ {
var query = from identityResource in DbSet.Include(x => x.UserClaims) var query = from identityResource in DbSet.Include(x => x.UserClaims)
where scopeNames.Contains(identityResource.Name) where scopeNames.Contains(identityResource.Name)
@ -31,7 +31,7 @@ namespace Volo.Abp.IdentityServer
return await query.ToListAsync(); return await query.ToListAsync();
} }
public async Task<List<ApiResource>> FindApiResourcesByScopeAsync(string[] scopeNames) public virtual async Task<List<ApiResource>> FindApiResourcesByScopeAsync(string[] scopeNames)
{ {
var query = from api in DbContext.ApiResources var query = from api in DbContext.ApiResources
where api.Scopes.Any(x => scopeNames.Contains(x.Name)) where api.Scopes.Any(x => scopeNames.Contains(x.Name))
@ -46,7 +46,7 @@ namespace Volo.Abp.IdentityServer
return await query.ToListAsync(); return await query.ToListAsync();
} }
public async Task<ApiResource> FindApiResourceAsync(string name) public virtual async Task<ApiResource> FindApiResourceAsync(string name)
{ {
var query = from apiResource in DbContext.ApiResources var query = from apiResource in DbContext.ApiResources
where apiResource.Name == name where apiResource.Name == name
@ -61,7 +61,7 @@ namespace Volo.Abp.IdentityServer
return await query.FirstOrDefaultAsync(); return await query.FirstOrDefaultAsync();
} }
public async Task<ApiAndIdentityResources> GetAllResourcesAsync() public virtual async Task<ApiAndIdentityResources> GetAllResourcesAsync()
{ {
var identity = DbContext.IdentityResources var identity = DbContext.IdentityResources
.Include(x => x.UserClaims); .Include(x => x.UserClaims);

2
src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs

@ -60,7 +60,7 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
return base.Insert(entity, autoSave); return base.Insert(entity, autoSave);
} }
private void SetIdIfNeeded(TEntity entity) protected virtual void SetIdIfNeeded(TEntity entity)
{ {
if (typeof(TKey) == typeof(int) || typeof(TKey) == typeof(long) || typeof(TKey) == typeof(Guid)) if (typeof(TKey) == typeof(int) || typeof(TKey) == typeof(long) || typeof(TKey) == typeof(Guid))
{ {

2
src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -140,7 +140,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
return Builders<TEntity>.Filter.Eq(e => e.Id, entity.Id); return Builders<TEntity>.Filter.Eq(e => e.Id, entity.Id);
} }
private static FilterDefinition<TEntity> CreateEntityFilter(TKey id) protected virtual FilterDefinition<TEntity> CreateEntityFilter(TKey id)
{ {
return Builders<TEntity>.Filter.Eq(e => e.Id, id); return Builders<TEntity>.Filter.Eq(e => e.Id, id);
} }

10
src/Volo.Abp.MultiTenancy.EntityFrameworkCore/Volo/Abp/MultiTenancy/EfCoreTenantRepository.cs

@ -19,32 +19,32 @@ namespace Volo.Abp.MultiTenancy
} }
public async Task<Tenant> FindByNameAsync(string name, CancellationToken cancellationToken = default) public virtual async Task<Tenant> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.FirstOrDefaultAsync(t => t.Name == name, cancellationToken); .FirstOrDefaultAsync(t => t.Name == name, cancellationToken);
} }
public async Task<Tenant> FindByNameIncludeDetailsAsync(string name, CancellationToken cancellationToken = default) public virtual async Task<Tenant> FindByNameIncludeDetailsAsync(string name, CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.Include(t => t.ConnectionStrings) //TODO: Why not creating a virtual Include method in EfCoreRepository and override to add included properties to be available for every query..? .Include(t => t.ConnectionStrings) //TODO: Why not creating a virtual Include method in EfCoreRepository and override to add included properties to be available for every query..?
.FirstOrDefaultAsync(t => t.Name == name, cancellationToken); .FirstOrDefaultAsync(t => t.Name == name, cancellationToken);
} }
public async Task<Tenant> FindWithIncludeDetailsAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<Tenant> FindWithIncludeDetailsAsync(Guid id, CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.Include(t => t.ConnectionStrings) .Include(t => t.ConnectionStrings)
.FirstOrDefaultAsync(t => t.Id == id, cancellationToken); .FirstOrDefaultAsync(t => t.Id == id, cancellationToken);
} }
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{ {
return await DbSet.LongCountAsync(cancellationToken); return await DbSet.LongCountAsync(cancellationToken);
} }
public async Task<List<Tenant>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default) public virtual async Task<List<Tenant>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default)
{ {
return await this.WhereIf( return await this.WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),

Loading…
Cancel
Save