From a4dda7a9fc981b1beb4df4b55b969d4a65e4a012 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 14 Jun 2020 21:31:24 +0200 Subject: [PATCH 01/10] Splitted `ICrudAppService` interface --- .../Application/Services/ICreateAppService.cs | 19 +++++++++++++ .../Services/ICreateUpdateAppService.cs | 26 +++++++++++++++++ .../Application/Services/ICrudAppService.cs | 14 ++++------ .../Application/Services/IDeleteAppService.cs | 12 ++++++++ .../Services/IReadOnlyAppService.cs | 28 +++++++++++++++++++ .../Application/Services/IUpdateAppService.cs | 19 +++++++++++++ 6 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs new file mode 100644 index 0000000000..bd9a4f4620 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Volo.Abp.Application.Services +{ + public interface ICreateAppService + : ICreateAppService + { + + } + + public interface ICreateAppService + : IApplicationService + { + Task CreateAsync(TCreateInput input); + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs new file mode 100644 index 0000000000..12362e9b73 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Volo.Abp.Application.Services +{ + public interface ICreateUpdateAppService + : ICreateUpdateAppService + { + + } + + public interface ICreateUpdateAppService + : ICreateUpdateAppService + { + + } + + public interface ICreateUpdateAppService + : ICreateAppService + , IUpdateAppService + , IApplicationService + { + + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs index 12f3b51d11..b3b873cd5b 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; + using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services @@ -28,16 +29,11 @@ namespace Volo.Abp.Application.Services } public interface ICrudAppService - : IApplicationService + : IReadOnlyAppService + , ICreateUpdateAppService + , IDeleteAppService + , IApplicationService { - Task GetAsync(TKey id); - - Task> GetListAsync(TGetListInput input); - - Task CreateAsync(TCreateInput input); - - Task UpdateAsync(TKey id, TUpdateInput input); - Task DeleteAsync(TKey id); } } diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs new file mode 100644 index 0000000000..0a70e2a95e --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Volo.Abp.Application.Services +{ + public interface IDeleteAppService : IApplicationService + { + Task DeleteAsync(TKey id); + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs new file mode 100644 index 0000000000..2f4ad1b9c7 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.Application.Services +{ + public interface IReadOnlyAppService + : IReadOnlyAppService + { + + } + + public interface IReadOnlyAppService + : IReadOnlyAppService + { + + } + + public interface IReadOnlyAppService + { + Task GetAsync(TKey id); + + Task> GetListAsync(TGetListInput input); + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs new file mode 100644 index 0000000000..043050b170 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Volo.Abp.Application.Services +{ + public interface IUpdateAppService + : IUpdateAppService + { + + } + + public interface IUpdateAppService + : IApplicationService + { + Task UpdateAsync(TKey id, TUpdateInput input); + } +} From 10c00be2dc39e6d2c39328466ee1b77bad890e95 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 14 Jun 2020 22:20:11 +0200 Subject: [PATCH 02/10] Implemented rudimentary readonly appservices --- .../Services/AbstractKeyReadOnlyAppService.cs | 185 ++++++++++++++++++ .../Services/ReadOnlyAppService.cs | 45 +++++ 2 files changed, 230 insertions(+) create mode 100644 framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs new file mode 100644 index 0000000000..c6a971cf5d --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs @@ -0,0 +1,185 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Text; +using System.Threading.Tasks; + +using Volo.Abp.Application.Dtos; +using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services +{ + public abstract class AbstractKeyReadOnlyAppService + : AbstractKeyReadOnlyAppService + where TEntity : class, IEntity + { + protected AbstractKeyReadOnlyAppService(IRepository repository) + : base(repository) + { + } + } + + public abstract class AbstractKeyReadOnlyAppService + : AbstractKeyReadOnlyAppService + where TEntity : class, IEntity + { + protected AbstractKeyReadOnlyAppService(IRepository repository) + : base(repository) + { + } + } + + public abstract class AbstractKeyReadOnlyAppService + : ApplicationService + , IReadOnlyAppService + where TEntity : class, IEntity + { + protected IRepository Repository { get; } + + protected virtual string GetPolicyName { get; set; } + + protected virtual string GetListPolicyName { get; set; } + + protected AbstractKeyReadOnlyAppService(IRepository repository) + { + Repository = repository; + } + + public virtual async Task GetAsync(TKey id) + { + await CheckGetPolicyAsync(); + + var entity = await GetEntityByIdAsync(id); + return MapToGetOutputDto(entity); + } + + public virtual async Task> GetListAsync(TGetListInput input) + { + await CheckGetListPolicyAsync(); + + var query = CreateFilteredQuery(input); + + var totalCount = await AsyncExecuter.CountAsync(query); + + query = ApplySorting(query, input); + query = ApplyPaging(query, input); + + var entities = await AsyncExecuter.ToListAsync(query); + + return new PagedResultDto( + totalCount, + entities.Select(MapToGetListOutputDto).ToList() + ); + } + + protected abstract Task GetEntityByIdAsync(TKey id); + + protected virtual async Task CheckGetPolicyAsync() + { + await CheckPolicyAsync(GetPolicyName); + } + + protected virtual async Task CheckGetListPolicyAsync() + { + await CheckPolicyAsync(GetListPolicyName); + } + + /// + /// Should apply sorting if needed. + /// + /// The query. + /// The input. + protected virtual IQueryable ApplySorting(IQueryable query, TGetListInput input) + { + //Try to sort query if available + if (input is ISortedResultRequest sortInput) + { + if (!sortInput.Sorting.IsNullOrWhiteSpace()) + { + return query.OrderBy(sortInput.Sorting); + } + } + + //IQueryable.Task requires sorting, so we should sort if Take will be used. + if (input is ILimitedResultRequest) + { + return ApplyDefaultSorting(query); + } + + //No sorting + return query; + } + + /// + /// Applies sorting if no sorting specified but a limited result requested. + /// + /// The query. + protected virtual IQueryable ApplyDefaultSorting(IQueryable query) + { + if (typeof(TEntity).IsAssignableTo()) + { + return query.OrderByDescending(e => ((ICreationAuditedObject)e).CreationTime); + } + + throw new AbpException("No sorting specified but this query requires sorting. Override the ApplyDefaultSorting method for your application service derived from AbstractKeyCrudAppService!"); + } + + /// + /// Should apply paging if needed. + /// + /// The query. + /// The input. + protected virtual IQueryable ApplyPaging(IQueryable query, TGetListInput input) + { + //Try to use paging if available + if (input is IPagedResultRequest pagedInput) + { + return query.PageBy(pagedInput); + } + + //Try to limit query result if available + if (input is ILimitedResultRequest limitedInput) + { + return query.Take(limitedInput.MaxResultCount); + } + + //No paging + return query; + } + + /// + /// This method should create based on given input. + /// It should filter query if needed, but should not do sorting or paging. + /// Sorting should be done in and paging should be done in + /// methods. + /// + /// The input. + protected virtual IQueryable CreateFilteredQuery(TGetListInput input) + { + return Repository; + } + + /// + /// Maps to . + /// It uses by default. + /// It can be overriden for custom mapping. + /// + protected virtual TGetOutputDto MapToGetOutputDto(TEntity entity) + { + return ObjectMapper.Map(entity); + } + + /// + /// Maps to . + /// It uses by default. + /// It can be overriden 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/ReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs new file mode 100644 index 0000000000..b1176dca85 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Volo.Abp.Application.Dtos; +using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services +{ + public abstract class ReadOnlyAppService + : AbstractKeyReadOnlyAppService + where TEntity : class, IEntity + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto + { + protected new IRepository Repository { get; } + + protected ReadOnlyAppService(IRepository repository) + : base(repository) + { + Repository = repository; + } + + protected override async Task GetEntityByIdAsync(TKey id) + { + return await Repository.GetAsync(id); + } + + protected override IQueryable ApplyDefaultSorting(IQueryable query) + { + if (typeof(TEntity).IsAssignableTo()) + { + return query.OrderByDescending(e => ((ICreationAuditedObject)e).CreationTime); + } + else + { + return query.OrderByDescending(e => e.Id); + } + } + } +} From 85ec7f2e39e5030a6ba1f347df182ced18da8fda Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 14 Jun 2020 22:20:21 +0200 Subject: [PATCH 03/10] Updated inheritance chain --- .../Services/AbstractKeyCrudAppService.cs | 163 ++---------------- 1 file changed, 10 insertions(+), 153 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs index e6f433cad6..0fea4c31a5 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; + using Volo.Abp.Application.Dtos; using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; @@ -61,17 +62,10 @@ namespace Volo.Abp.Application.Services } public abstract class AbstractKeyCrudAppService - : ApplicationService, - ICrudAppService + : AbstractKeyReadOnlyAppService + , ICrudAppService where TEntity : class, IEntity { - - protected IRepository Repository { get; } - - protected virtual string GetPolicyName { get; set; } - - protected virtual string GetListPolicyName { get; set; } - protected virtual string CreatePolicyName { get; set; } protected virtual string UpdatePolicyName { get; set; } @@ -79,35 +73,9 @@ namespace Volo.Abp.Application.Services protected virtual string DeletePolicyName { get; set; } protected AbstractKeyCrudAppService(IRepository repository) + : base(repository) { - Repository = repository; - } - - public virtual async Task GetAsync(TKey id) - { - await CheckGetPolicyAsync(); - - var entity = await GetEntityByIdAsync(id); - return MapToGetOutputDto(entity); - } - - public virtual async Task> GetListAsync(TGetListInput input) - { - await CheckGetListPolicyAsync(); - var query = CreateFilteredQuery(input); - - var totalCount = await AsyncExecuter.CountAsync(query); - - query = ApplySorting(query, input); - query = ApplyPaging(query, input); - - var entities = await AsyncExecuter.ToListAsync(query); - - return new PagedResultDto( - totalCount, - entities.Select(MapToGetListOutputDto).ToList() - ); } public virtual async Task CreateAsync(TCreateInput input) @@ -144,18 +112,6 @@ namespace Volo.Abp.Application.Services protected abstract Task DeleteByIdAsync(TKey id); - protected abstract Task GetEntityByIdAsync(TKey id); - - protected virtual async Task CheckGetPolicyAsync() - { - await CheckPolicyAsync(GetPolicyName); - } - - protected virtual async Task CheckGetListPolicyAsync() - { - await CheckPolicyAsync(GetListPolicyName); - } - protected virtual async Task CheckCreatePolicyAsync() { await CheckPolicyAsync(CreatePolicyName); @@ -171,101 +127,6 @@ namespace Volo.Abp.Application.Services await CheckPolicyAsync(DeletePolicyName); } - /// - /// Should apply sorting if needed. - /// - /// The query. - /// The input. - protected virtual IQueryable ApplySorting(IQueryable query, TGetListInput input) - { - //Try to sort query if available - if (input is ISortedResultRequest sortInput) - { - if (!sortInput.Sorting.IsNullOrWhiteSpace()) - { - return query.OrderBy(sortInput.Sorting); - } - } - - //IQueryable.Task requires sorting, so we should sort if Take will be used. - if (input is ILimitedResultRequest) - { - return ApplyDefaultSorting(query); - } - - //No sorting - return query; - } - - /// - /// Applies sorting if no sorting specified but a limited result requested. - /// - /// The query. - protected virtual IQueryable ApplyDefaultSorting(IQueryable query) - { - if (typeof(TEntity).IsAssignableTo()) - { - return query.OrderByDescending(e => ((ICreationAuditedObject)e).CreationTime); - } - - throw new AbpException("No sorting specified but this query requires sorting. Override the ApplyDefaultSorting method for your application service derived from AbstractKeyCrudAppService!"); - } - - /// - /// Should apply paging if needed. - /// - /// The query. - /// The input. - protected virtual IQueryable ApplyPaging(IQueryable query, TGetListInput input) - { - //Try to use paging if available - if (input is IPagedResultRequest pagedInput) - { - return query.PageBy(pagedInput); - } - - //Try to limit query result if available - if (input is ILimitedResultRequest limitedInput) - { - return query.Take(limitedInput.MaxResultCount); - } - - //No paging - return query; - } - - /// - /// This method should create based on given input. - /// It should filter query if needed, but should not do sorting or paging. - /// Sorting should be done in and paging should be done in - /// methods. - /// - /// The input. - protected virtual IQueryable CreateFilteredQuery(TGetListInput input) - { - return Repository; - } - - /// - /// Maps to . - /// It uses by default. - /// It can be overriden for custom mapping. - /// - protected virtual TGetOutputDto MapToGetOutputDto(TEntity entity) - { - return ObjectMapper.Map(entity); - } - - /// - /// Maps to . - /// It uses by default. - /// It can be overriden for custom mapping. - /// - protected virtual TGetListOutputDto MapToGetListOutputDto(TEntity entity) - { - return ObjectMapper.Map(entity); - } - /// /// Maps to to create a new entity. /// It uses by default. @@ -284,18 +145,14 @@ namespace Volo.Abp.Application.Services /// protected virtual void SetIdForGuids(TEntity entity) { - var entityWithGuidId = entity as IEntity; - - if (entityWithGuidId == null || entityWithGuidId.Id != Guid.Empty) + if (entity is IEntity entityWithGuidId && entityWithGuidId.Id == Guid.Empty) { - return; + EntityHelper.TrySetId( + entityWithGuidId, + () => GuidGenerator.Create(), + true + ); } - - EntityHelper.TrySetId( - entityWithGuidId, - () => GuidGenerator.Create(), - true - ); } /// From e42586db496ba2f7dc5e3e55fd263ac825459b74 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 14 Jun 2020 22:25:16 +0200 Subject: [PATCH 04/10] code format --- .../Abp/Application/Services/ICreateUpdateAppService.cs | 6 +++--- .../Volo/Abp/Application/Services/ICrudAppService.cs | 8 ++++---- .../Abp/Application/Services/AbstractKeyCrudAppService.cs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs index 12362e9b73..22bf77ca96 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs @@ -17,9 +17,9 @@ namespace Volo.Abp.Application.Services } public interface ICreateUpdateAppService - : ICreateAppService - , IUpdateAppService - , IApplicationService + : ICreateAppService, + IUpdateAppService, + IApplicationService { } diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs index b3b873cd5b..b866ce0ed9 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs @@ -29,10 +29,10 @@ namespace Volo.Abp.Application.Services } public interface ICrudAppService - : IReadOnlyAppService - , ICreateUpdateAppService - , IDeleteAppService - , IApplicationService + : IReadOnlyAppService, + ICreateUpdateAppService, + IDeleteAppService, + IApplicationService { } diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs index 0fea4c31a5..9f234fbc3a 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs @@ -62,8 +62,8 @@ namespace Volo.Abp.Application.Services } public abstract class AbstractKeyCrudAppService - : AbstractKeyReadOnlyAppService - , ICrudAppService + : AbstractKeyReadOnlyAppService, + ICrudAppService where TEntity : class, IEntity { protected virtual string CreatePolicyName { get; set; } From 903faa6733a139cb3d66c6d9dbba42a1e7a0c3a0 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 14 Jun 2020 22:30:02 +0200 Subject: [PATCH 05/10] Added convenience classes --- .../Services/ReadOnlyAppService.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs index b1176dca85..69f1fd5077 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs @@ -11,6 +11,26 @@ using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Application.Services { + public abstract class ReadOnlyAppService + : ReadOnlyAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected ReadOnlyAppService(IRepository repository) : base(repository) + { + } + } + + public abstract class ReadOnlyAppService + : ReadOnlyAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected ReadOnlyAppService(IRepository repository) : base(repository) + { + } + } + public abstract class ReadOnlyAppService : AbstractKeyReadOnlyAppService where TEntity : class, IEntity From 34e3b992840cd01a85149c3bfccc08ca11f5f478 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Wed, 17 Jun 2020 18:27:14 +0200 Subject: [PATCH 06/10] Resolved code review issues by @liangshiw --- .../Volo/Abp/Application/Services/ICreateAppService.cs | 5 +---- .../Abp/Application/Services/ICreateUpdateAppService.cs | 9 ++------- .../Volo/Abp/Application/Services/ICrudAppService.cs | 5 +---- .../Volo/Abp/Application/Services/IDeleteAppService.cs | 5 +---- .../Volo/Abp/Application/Services/IReadOnlyAppService.cs | 6 ++---- .../Volo/Abp/Application/Services/IUpdateAppService.cs | 5 +---- 6 files changed, 8 insertions(+), 27 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs index bd9a4f4620..a5d75b0b4b 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateAppService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Volo.Abp.Application.Services { diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs index 22bf77ca96..ce3698405c 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICreateUpdateAppService.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Volo.Abp.Application.Services +namespace Volo.Abp.Application.Services { public interface ICreateUpdateAppService : ICreateUpdateAppService @@ -18,8 +14,7 @@ namespace Volo.Abp.Application.Services public interface ICreateUpdateAppService : ICreateAppService, - IUpdateAppService, - IApplicationService + IUpdateAppService { } diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs index b866ce0ed9..10f88db22a 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/ICrudAppService.cs @@ -1,5 +1,3 @@ -using System.Threading.Tasks; - using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services @@ -31,8 +29,7 @@ namespace Volo.Abp.Application.Services public interface ICrudAppService : IReadOnlyAppService, ICreateUpdateAppService, - IDeleteAppService, - IApplicationService + IDeleteAppService { } diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs index 0a70e2a95e..50badcead9 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IDeleteAppService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Volo.Abp.Application.Services { diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs index 2f4ad1b9c7..eb03faffe3 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Volo.Abp.Application.Dtos; @@ -20,6 +17,7 @@ namespace Volo.Abp.Application.Services } public interface IReadOnlyAppService + : IApplicationService { Task GetAsync(TKey id); diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs index 043050b170..c0904709bf 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IUpdateAppService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Volo.Abp.Application.Services { From 5646dce18a6d59b92a8aaf0ac6c54c97c73ac4ea Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Thu, 18 Jun 2020 21:01:46 +0200 Subject: [PATCH 07/10] Removed unused usings and unified code formatting --- .../Application/Services/AbstractKeyCrudAppService.cs | 4 ---- .../Services/AbstractKeyReadOnlyAppService.cs | 5 ++--- .../Volo/Abp/Application/Services/CrudAppService.cs | 2 +- .../Abp/Application/Services/ReadOnlyAppService.cs | 11 ++++++----- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs index 9f234fbc3a..e79f0ce75f 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs @@ -1,10 +1,6 @@ using System; -using System.Linq; -using System.Linq.Dynamic.Core; using System.Threading.Tasks; - using Volo.Abp.Application.Dtos; -using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.MultiTenancy; diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs index c6a971cf5d..e6af5484a7 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; -using System.Text; using System.Threading.Tasks; - using Volo.Abp.Application.Dtos; using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; @@ -19,6 +16,7 @@ namespace Volo.Abp.Application.Services protected AbstractKeyReadOnlyAppService(IRepository repository) : base(repository) { + } } @@ -29,6 +27,7 @@ namespace Volo.Abp.Application.Services protected AbstractKeyReadOnlyAppService(IRepository repository) : base(repository) { + } } 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 a2af0592a4..7832e8a4ab 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 @@ -70,7 +70,7 @@ namespace Volo.Abp.Application.Services protected new IRepository Repository { get; } protected CrudAppService(IRepository repository) - : base(repository) + : base(repository) { Repository = repository; } diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs index 69f1fd5077..0ddc4b4700 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; - using Volo.Abp.Application.Dtos; using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; @@ -16,8 +13,10 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected ReadOnlyAppService(IRepository repository) : base(repository) + protected ReadOnlyAppService(IRepository repository) + : base(repository) { + } } @@ -26,8 +25,10 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected ReadOnlyAppService(IRepository repository) : base(repository) + protected ReadOnlyAppService(IRepository repository) + : base(repository) { + } } From fba74dba0a1f1ce6402983477683f9be0c02ee0a Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 21 Jun 2020 14:58:03 +0200 Subject: [PATCH 08/10] Removed empty line between usings --- .../Volo/Abp/Application/Services/IReadOnlyAppService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs index eb03faffe3..09df0dc9cd 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IReadOnlyAppService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; - using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services From a84e31143c696c39c9e894bcc83fcb4e78274a8f Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Thu, 25 Jun 2020 10:09:59 +0200 Subject: [PATCH 09/10] Optimized repositories in readonly application services --- .../Abp/Application/Services/AbstractKeyCrudAppService.cs | 4 +++- .../Application/Services/AbstractKeyReadOnlyAppService.cs | 8 ++++---- .../Volo/Abp/Application/Services/ReadOnlyAppService.cs | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs index e79f0ce75f..ce44a22455 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs @@ -62,6 +62,8 @@ namespace Volo.Abp.Application.Services ICrudAppService where TEntity : class, IEntity { + protected new IRepository Repository { get; } + protected virtual string CreatePolicyName { get; set; } protected virtual string UpdatePolicyName { get; set; } @@ -71,7 +73,7 @@ namespace Volo.Abp.Application.Services protected AbstractKeyCrudAppService(IRepository repository) : base(repository) { - + Repository = repository; } public virtual async Task CreateAsync(TCreateInput input) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs index e6af5484a7..45dff23852 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs @@ -13,7 +13,7 @@ namespace Volo.Abp.Application.Services : AbstractKeyReadOnlyAppService where TEntity : class, IEntity { - protected AbstractKeyReadOnlyAppService(IRepository repository) + protected AbstractKeyReadOnlyAppService(IReadOnlyRepository repository) : base(repository) { @@ -24,7 +24,7 @@ namespace Volo.Abp.Application.Services : AbstractKeyReadOnlyAppService where TEntity : class, IEntity { - protected AbstractKeyReadOnlyAppService(IRepository repository) + protected AbstractKeyReadOnlyAppService(IReadOnlyRepository repository) : base(repository) { @@ -36,13 +36,13 @@ namespace Volo.Abp.Application.Services , IReadOnlyAppService where TEntity : class, IEntity { - protected IRepository Repository { get; } + protected IReadOnlyRepository Repository { get; } protected virtual string GetPolicyName { get; set; } protected virtual string GetListPolicyName { get; set; } - protected AbstractKeyReadOnlyAppService(IRepository repository) + protected AbstractKeyReadOnlyAppService(IReadOnlyRepository repository) { Repository = repository; } diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs index 0ddc4b4700..d99928126c 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs @@ -13,7 +13,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected ReadOnlyAppService(IRepository repository) + protected ReadOnlyAppService(IReadOnlyRepository repository) : base(repository) { @@ -25,7 +25,7 @@ namespace Volo.Abp.Application.Services where TEntity : class, IEntity where TEntityDto : IEntityDto { - protected ReadOnlyAppService(IRepository repository) + protected ReadOnlyAppService(IReadOnlyRepository repository) : base(repository) { @@ -38,9 +38,9 @@ namespace Volo.Abp.Application.Services where TGetOutputDto : IEntityDto where TGetListOutputDto : IEntityDto { - protected new IRepository Repository { get; } + protected new IReadOnlyRepository Repository { get; } - protected ReadOnlyAppService(IRepository repository) + protected ReadOnlyAppService(IReadOnlyRepository repository) : base(repository) { Repository = repository; From 0b76186928c2e28b4a0fe856f852cc4c8a187440 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Mon, 29 Jun 2020 09:09:52 +0200 Subject: [PATCH 10/10] Used different names for `ReadOnlyRepository` and `Repository` in application services Still using `protected new` on `CrudAppService` because the repository member in `AbstractKeyCrudAppService` has to be renamed to something like `AbstractKeyRepository`, which would be a breaking change. Renaming the repository in each descendant could lead to misunderstandings, since in `CrudAppService` descendants will be three repositories to choose from: `Repository`, `ReadOnlyRepository`, `AbstractKeyRepository`. Currently the user must only differ between `ReadOnlyRepository` and `Repository`. @maliming, can you review this? --- .../Abp/Application/Services/AbstractKeyCrudAppService.cs | 2 +- .../Application/Services/AbstractKeyReadOnlyAppService.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs index ce44a22455..11550c456f 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs @@ -62,7 +62,7 @@ namespace Volo.Abp.Application.Services ICrudAppService where TEntity : class, IEntity { - protected new IRepository Repository { get; } + protected IRepository Repository { get; } protected virtual string CreatePolicyName { get; set; } diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs index 45dff23852..9085434211 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs @@ -36,7 +36,7 @@ namespace Volo.Abp.Application.Services , IReadOnlyAppService where TEntity : class, IEntity { - protected IReadOnlyRepository Repository { get; } + protected IReadOnlyRepository ReadOnlyRepository { get; } protected virtual string GetPolicyName { get; set; } @@ -44,7 +44,7 @@ namespace Volo.Abp.Application.Services protected AbstractKeyReadOnlyAppService(IReadOnlyRepository repository) { - Repository = repository; + ReadOnlyRepository = repository; } public virtual async Task GetAsync(TKey id) @@ -123,7 +123,7 @@ namespace Volo.Abp.Application.Services return query.OrderByDescending(e => ((ICreationAuditedObject)e).CreationTime); } - throw new AbpException("No sorting specified but this query requires sorting. Override the ApplyDefaultSorting method for your application service derived from AbstractKeyCrudAppService!"); + throw new AbpException("No sorting specified but this query requires sorting. Override the ApplyDefaultSorting method for your application service derived from AbstractKeyReadOnlyAppService!"); } /// @@ -158,7 +158,7 @@ namespace Volo.Abp.Application.Services /// The input. protected virtual IQueryable CreateFilteredQuery(TGetListInput input) { - return Repository; + return ReadOnlyRepository; } ///