Browse Source

checking Use(Object/List)ProjectionMapper before resolving the mapper

pull/26016/head
Mohamed Nazem 22 hours ago
committed by GitHub
parent
commit
632addf8e8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 32
      framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs

32
framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs

@ -44,11 +44,9 @@ public abstract class AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGet
protected virtual string? GetListPolicyName { get; set; }
protected virtual IQueryProjectionMapper<TEntity, TGetOutputDto>? ObjectProjectionMapper =>
LazyServiceProvider.LazyGetService<IQueryProjectionMapper<TEntity, TGetOutputDto>>();
protected virtual IQueryProjectionMapper<TEntity, TGetOutputDto>? ObjectProjectionMapper { get; }
protected virtual IQueryProjectionMapper<TEntity, TGetListOutputDto>? ListProjectionMapper =>
LazyServiceProvider.LazyGetService<IQueryProjectionMapper<TEntity, TGetListOutputDto>>();
protected virtual IQueryProjectionMapper<TEntity, TGetListOutputDto>? ListProjectionMapper { get; }
protected virtual bool UseObjectProjectionMapper =>
ObjectProjectionMapper != null;
@ -59,20 +57,28 @@ public abstract class AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGet
protected AbstractKeyReadOnlyAppService(IReadOnlyRepository<TEntity> repository)
{
ReadOnlyRepository = repository;
ObjectProjectionMapper =
LazyServiceProvider.LazyGetService<
IQueryProjectionMapper<TEntity, TGetOutputDto>>();
ListProjectionMapper =
LazyServiceProvider.LazyGetService<
IQueryProjectionMapper<TEntity, TGetListOutputDto>>();
}
public virtual async Task<TGetOutputDto> GetAsync(TKey id)
{
await CheckGetPolicyAsync();
var projectionMapper = ObjectProjectionMapper;
if (UseObjectProjectionMapper && projectionMapper != null)
if (UseObjectProjectionMapper && ObjectProjectionMapper != null)
{
var query = await GetEntityByIdQueryAsync(id);
var dto =
await AsyncExecuter.FirstOrDefaultAsync(projectionMapper.ProjectTo(query))
var dto =
await AsyncExecuter.FirstOrDefaultAsync(
ObjectProjectionMapper.ProjectTo(query)
)
?? throw new EntityNotFoundException(typeof(TEntity), id);
return dto;
@ -97,12 +103,10 @@ public abstract class AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGet
query = ApplySorting(query, input);
query = ApplyPaging(query, input);
var projectionMapper = ListProjectionMapper;
if (UseListProjectionMapper && projectionMapper != null)
if (UseListProjectionMapper && ListProjectionMapper != null)
{
entityDtos = await AsyncExecuter.ToListAsync(
projectionMapper.ProjectTo(query)
ListProjectionMapper.ProjectTo(query)
);
}
else
@ -124,7 +128,7 @@ public abstract class AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGet
{
throw new NotImplementedException(
"Override this method to create the query used for getting an entity by id."
);
);
}
protected virtual async Task CheckGetPolicyAsync()

Loading…
Cancel
Save