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

pull/206/head
Halil İbrahim Kalkan 8 years ago
parent f4f49bb935
commit eebd0e76b6

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

@ -76,22 +76,22 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
}
}
public virtual Task EnsureCollectionLoadedAsync<TProperty>(
public virtual async Task EnsureCollectionLoadedAsync<TProperty>(
TEntity entity,
Expression<Func<TEntity, IEnumerable<TProperty>>> propertyExpression,
CancellationToken cancellationToken = default)
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,
Expression<Func<TEntity, TProperty>> propertyExpression,
CancellationToken cancellationToken = default)
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);
@ -137,9 +137,9 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
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)

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

@ -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
.OrderBy(sorting ?? nameof(IdentityRole.Name))
@ -31,7 +31,7 @@ namespace Volo.Abp.Identity
.ToListAsync();
}
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await this.LongCountAsync(cancellationToken);
}

@ -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
join role in DbContext.Roles on userRole.RoleId equals role.Id
where userRole.UserId.Equals(userId)
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
.Where(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey)
.FirstOrDefaultAsync(cancellationToken);
@ -49,12 +48,12 @@ namespace Volo.Abp.Identity
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
join user in DbContext.Users on userclaims.UserId equals user.Id
@ -64,7 +63,7 @@ namespace Volo.Abp.Identity
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);
@ -81,7 +80,7 @@ namespace Volo.Abp.Identity
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(
!filter.IsNullOrWhiteSpace(),
@ -94,12 +93,12 @@ namespace Volo.Abp.Identity
.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();
}
public async Task<List<IdentityRole>> GetRolesAsync(Guid userId)
public virtual async Task<List<IdentityRole>> GetRolesAsync(Guid userId)
{
var query = from userRole in DbContext.UserRoles
join role in DbContext.Roles on userRole.RoleId equals role.Id
@ -109,7 +108,7 @@ namespace Volo.Abp.Identity
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);
}

@ -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);
}

@ -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.RedirectUris)
.Include(x => x.PostLogoutRedirectUris)

@ -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)
where scopeNames.Contains(identityResource.Name)
@ -31,7 +31,7 @@ namespace Volo.Abp.IdentityServer
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
where api.Scopes.Any(x => scopeNames.Contains(x.Name))
@ -46,7 +46,7 @@ namespace Volo.Abp.IdentityServer
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
where apiResource.Name == name
@ -61,7 +61,7 @@ namespace Volo.Abp.IdentityServer
return await query.FirstOrDefaultAsync();
}
public async Task<ApiAndIdentityResources> GetAllResourcesAsync()
public virtual async Task<ApiAndIdentityResources> GetAllResourcesAsync()
{
var identity = DbContext.IdentityResources
.Include(x => x.UserClaims);

@ -60,7 +60,7 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
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))
{

@ -140,7 +140,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
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);
}

@ -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
.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
.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);
}
public async Task<Tenant> FindWithIncludeDetailsAsync(Guid id, CancellationToken cancellationToken = default)
public virtual async Task<Tenant> FindWithIncludeDetailsAsync(Guid id, CancellationToken cancellationToken = default)
{
return await DbSet
.Include(t => t.ConnectionStrings)
.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);
}
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(
!filter.IsNullOrWhiteSpace(),

Loading…
Cancel
Save