diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs index 151212925a..249c892b6e 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs @@ -45,28 +45,40 @@ namespace Volo.Abp.Application.Services } public abstract class AsyncCrudAppService - : CrudAppServiceBase, - IAsyncCrudAppService + : AsyncCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected AsyncCrudAppService(IRepository repository) + : base(repository) + { + } + } + + public abstract class AsyncCrudAppService + : CrudAppServiceBase, + IAsyncCrudAppService where TEntity : class, IEntity - where TEntityDto : IEntityDto + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto { public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; } protected AsyncCrudAppService(IRepository repository) - :base(repository) + : base(repository) { AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance; } - public virtual async Task GetAsync(TKey id) + public virtual async Task GetAsync(TKey id) { await CheckGetPolicyAsync(); var entity = await GetEntityByIdAsync(id); - return MapToEntityDto(entity); + return MapToGetOutputDto(entity); } - public virtual async Task> GetListAsync(TGetListInput input) + public virtual async Task> GetListAsync(TGetListInput input) { await CheckGetListPolicyAsync(); @@ -79,29 +91,29 @@ namespace Volo.Abp.Application.Services var entities = await AsyncQueryableExecuter.ToListAsync(query); - return new PagedResultDto( + return new PagedResultDto( totalCount, - entities.Select(MapToEntityDto).ToList() + entities.Select(MapToGetListOutputDto).ToList() ); } - public virtual async Task CreateAsync(TCreateInput input) + public virtual async Task CreateAsync(TCreateInput input) { await CheckCreatePolicyAsync(); var entity = MapToEntity(input); - - if(entity is IMultiTenant && !HasTenantIdProperty(entity)) + + if (entity is IMultiTenant && !HasTenantIdProperty(entity)) { TryToSetTenantId(entity); } - + await Repository.InsertAsync(entity, autoSave: true); - return MapToEntityDto(entity); + return MapToGetOutputDto(entity); } - public virtual async Task UpdateAsync(TKey id, TUpdateInput input) + public virtual async Task UpdateAsync(TKey id, TUpdateInput input) { await CheckUpdatePolicyAsync(); @@ -110,7 +122,7 @@ namespace Volo.Abp.Application.Services MapToEntity(input, entity); await Repository.UpdateAsync(entity, autoSave: true); - return MapToEntityDto(entity); + return MapToGetOutputDto(entity); } public virtual async Task DeleteAsync(TKey id) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs index 2595bc6edd..7b79823e80 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs @@ -44,8 +44,7 @@ namespace Volo.Abp.Application.Services } public abstract class CrudAppService - : CrudAppServiceBase, - ICrudAppService + : CrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto { @@ -54,16 +53,30 @@ namespace Volo.Abp.Application.Services { } + } - public virtual TEntityDto Get(TKey id) + public abstract class CrudAppService + : CrudAppServiceBase, + ICrudAppService + where TEntity : class, IEntity + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto + { + protected CrudAppService(IRepository repository) + : base(repository) + { + + } + + public virtual TGetOutputDto Get(TKey id) { CheckGetPolicy(); var entity = GetEntityById(id); - return MapToEntityDto(entity); + return MapToGetOutputDto(entity); } - public virtual PagedResultDto GetList(TGetListInput input) + public virtual PagedResultDto GetList(TGetListInput input) { CheckGetListPolicy(); @@ -76,29 +89,29 @@ namespace Volo.Abp.Application.Services var entities = query.ToList(); - return new PagedResultDto( + return new PagedResultDto( totalCount, - entities.Select(MapToEntityDto).ToList() + entities.Select(MapToGetListOutputDto).ToList() ); } - public virtual TEntityDto Create(TCreateInput input) + public virtual TGetOutputDto Create(TCreateInput input) { CheckCreatePolicy(); var entity = MapToEntity(input); - - if(entity is IMultiTenant && !HasTenantIdProperty(entity)) + + if (entity is IMultiTenant && !HasTenantIdProperty(entity)) { TryToSetTenantId(entity); } - + Repository.Insert(entity, autoSave: true); - return MapToEntityDto(entity); + return MapToGetOutputDto(entity); } - public virtual TEntityDto Update(TKey id, TUpdateInput input) + public virtual TGetOutputDto Update(TKey id, TUpdateInput input) { CheckUpdatePolicy(); @@ -106,7 +119,7 @@ namespace Volo.Abp.Application.Services MapToEntity(input, entity); Repository.Update(entity, autoSave: true); - return MapToEntityDto(entity); + return MapToGetOutputDto(entity); } public virtual void Delete(TKey id) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs index b678362c53..e9c6610202 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs @@ -13,10 +13,11 @@ namespace Volo.Abp.Application.Services /// This is a common base class for CrudAppService and AsyncCrudAppService classes. /// Inherit either from CrudAppService or AsyncCrudAppService, not from this class. /// - public abstract class CrudAppServiceBase : + public abstract class CrudAppServiceBase : ApplicationService where TEntity : class, IEntity - where TEntityDto : IEntityDto + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto { protected IRepository Repository { get; } @@ -100,13 +101,23 @@ namespace Volo.Abp.Application.Services } /// - /// Maps to . + /// Maps to . /// It uses by default. /// It can be overrided for custom mapping. /// - protected virtual TEntityDto MapToEntityDto(TEntity entity) + protected virtual TGetOutputDto MapToGetOutputDto(TEntity entity) { - return ObjectMapper.Map(entity); + return ObjectMapper.Map(entity); + } + + /// + /// Maps to . + /// It uses by default. + /// It can be overrided for custom mapping. + /// + protected virtual TGetListOutputDto MapToGetListOutputDto(TEntity entity) + { + return ObjectMapper.Map(entity); } /// diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IAsyncCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IAsyncCrudAppService.cs index 4f97c49ae0..e3e18f4873 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IAsyncCrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IAsyncCrudAppService.cs @@ -25,16 +25,24 @@ namespace Volo.Abp.Application.Services } public interface IAsyncCrudAppService - : IApplicationService + : IAsyncCrudAppService where TEntityDto : IEntityDto { - Task GetAsync(TKey id); - Task> GetListAsync(TGetListInput input); + } + + public interface IAsyncCrudAppService + : IApplicationService + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto + { + Task GetAsync(TKey id); + + Task> GetListAsync(TGetListInput input); - Task CreateAsync(TCreateInput input); + Task CreateAsync(TCreateInput input); - Task UpdateAsync(TKey id, TUpdateInput input); + Task UpdateAsync(TKey id, TUpdateInput input); Task DeleteAsync(TKey id); } diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs index 7e8b96b9f8..2f3b770849 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs @@ -24,16 +24,24 @@ namespace Volo.Abp.Application.Services } public interface ICrudAppService - : IApplicationService + : ICrudAppService where TEntityDto : IEntityDto { - TEntityDto Get(TKey id); - PagedResultDto GetList(TGetListInput input); + } + + public interface ICrudAppService + : IApplicationService + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto + { + TGetOutputDto Get(TKey id); + + PagedResultDto GetList(TGetListInput input); - TEntityDto Create(TCreateInput input); + TGetOutputDto Create(TCreateInput input); - TEntityDto Update(TKey id, TUpdateInput input); + TGetOutputDto Update(TKey id, TUpdateInput input); void Delete(TKey id); }