diff --git a/src/AbpDesk/AbpDesk.Application/AbpDesk.Application.csproj b/src/AbpDesk/AbpDesk.Application/AbpDesk.Application.csproj index 356b57864d..78b767ebea 100644 --- a/src/AbpDesk/AbpDesk.Application/AbpDesk.Application.csproj +++ b/src/AbpDesk/AbpDesk.Application/AbpDesk.Application.csproj @@ -12,6 +12,7 @@ + diff --git a/src/AbpDesk/AbpDesk.Application/AbpDesk/AbpDeskApplicationModule.cs b/src/AbpDesk/AbpDesk.Application/AbpDesk/AbpDeskApplicationModule.cs index 57091e9966..8eca7c59cb 100644 --- a/src/AbpDesk/AbpDesk.Application/AbpDesk/AbpDeskApplicationModule.cs +++ b/src/AbpDesk/AbpDesk.Application/AbpDesk/AbpDeskApplicationModule.cs @@ -1,14 +1,23 @@ using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; namespace AbpDesk { - [DependsOn(typeof(AbpDeskDomainModule))] + [DependsOn(typeof(AbpDeskDomainModule), typeof(AbpAutoMapperModule))] public class AbpDeskApplicationModule : AbpModule { public override void ConfigureServices(IServiceCollection services) { services.AddAssemblyOf(); + + services.Configure(options => + { + options.Configurators.Add(context => + { + context.MapperConfiguration.AddProfile(); + }); + }); } } } diff --git a/src/AbpDesk/AbpDesk.Application/AbpDesk/AbpDeskApplicationModuleAutoMapperProfile.cs b/src/AbpDesk/AbpDesk.Application/AbpDesk/AbpDeskApplicationModuleAutoMapperProfile.cs new file mode 100644 index 0000000000..acb99dee2e --- /dev/null +++ b/src/AbpDesk/AbpDesk.Application/AbpDesk/AbpDeskApplicationModuleAutoMapperProfile.cs @@ -0,0 +1,14 @@ +using AbpDesk.Tickets; +using AbpDesk.Tickets.Dtos; +using AutoMapper; + +namespace AbpDesk +{ + public class AbpDeskApplicationModuleAutoMapperProfile : Profile + { + public AbpDeskApplicationModuleAutoMapperProfile() + { + CreateMap(); + } + } +} \ No newline at end of file diff --git a/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs b/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs index 29af97062b..db62a39d24 100644 --- a/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs +++ b/src/AbpDesk/AbpDesk.Application/AbpDesk/Tickets/TicketAppService.cs @@ -1,6 +1,8 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using AbpDesk.Tickets.Dtos; +using Volo.Abp.Application.Services; using Volo.Abp.Application.Services.Dtos; using Volo.Abp.Domain.Repositories; using Volo.Abp.Linq; @@ -9,15 +11,14 @@ using Volo.ExtensionMethods; namespace AbpDesk.Tickets { - public class TicketAppService : ITicketAppService + public class TicketAppService : ApplicationService, ITicketAppService { private readonly IQueryableRepository _ticketRepository; private readonly IAsyncQueryableExecuter _asyncQueryableExecuter; public TicketAppService( IQueryableRepository ticketRepository, - IAsyncQueryableExecuter asyncQueryableExecuter - ) + IAsyncQueryableExecuter asyncQueryableExecuter) { _ticketRepository = ticketRepository; _asyncQueryableExecuter = asyncQueryableExecuter; @@ -30,14 +31,11 @@ namespace AbpDesk.Tickets !input.Filter.IsNullOrWhiteSpace(), t => t.Title.Contains(input.Filter) || t.Body.Contains(input.Filter) ) - .Select(t => new TicketDto - { - Id = t.Id, - Title = t.Title, - Body = t.Body - })); + ); - return new ListResultDto(tickets); + return new ListResultDto( + ObjectMapper.Map, List>(tickets) + ); } public ListResultDto GetAll2(GetAllTicketsInput input) @@ -47,15 +45,11 @@ namespace AbpDesk.Tickets !input.Filter.IsNullOrWhiteSpace(), t => t.Title.Contains(input.Filter) || t.Body.Contains(input.Filter) ) - .Select(t => new TicketDto - { - Id = t.Id, - Title = t.Title, - Body = t.Body - }) .ToList(); - return new ListResultDto(tickets); + return new ListResultDto( + ObjectMapper.Map, List>(tickets) + ); } } } diff --git a/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs b/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs index 5285e55887..afc09e3a08 100644 --- a/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs +++ b/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs @@ -98,7 +98,7 @@ namespace Volo.Abp.AutoMapper foreach (var type in types) { logger.LogDebug(type.FullName); - context.MapperConfigurationExpression.CreateAutoAttributeMaps(type); + context.MapperConfiguration.CreateAutoAttributeMaps(type); } } diff --git a/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperOptions.cs b/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperOptions.cs index 38d0c37df4..a98bb88dbd 100644 --- a/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperOptions.cs +++ b/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperOptions.cs @@ -19,21 +19,21 @@ namespace Volo.Abp.AutoMapper public interface IAbpAutoMapperConfigurationContext { - IMapperConfigurationExpression MapperConfigurationExpression { get; } + IMapperConfigurationExpression MapperConfiguration { get; } IServiceProvider ServiceProvider { get; } } public class AbpAutoMapperConfigurationContext : IAbpAutoMapperConfigurationContext { - public IMapperConfigurationExpression MapperConfigurationExpression { get; } + public IMapperConfigurationExpression MapperConfiguration { get; } public IServiceProvider ServiceProvider { get; } public AbpAutoMapperConfigurationContext( IMapperConfigurationExpression mapperConfigurationExpression, IServiceProvider serviceProvider) { - MapperConfigurationExpression = mapperConfigurationExpression; + MapperConfiguration = mapperConfigurationExpression; ServiceProvider = serviceProvider; } } diff --git a/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs b/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs index b9a41dda9d..27ad7f5b36 100644 --- a/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs +++ b/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs @@ -15,6 +15,8 @@ namespace Autofac.Builder IServiceCollection services) where TConcreteReflectionActivatorData : ConcreteReflectionActivatorData { + registrationBuilder = registrationBuilder.PropertiesAutowired(); + var serviceType = registrationBuilder.RegistrationData.Services.OfType().FirstOrDefault()?.ServiceType; if (serviceType == null) { diff --git a/src/Volo.Abp.Identity.Application/Volo.Abp.Identity.Application.csproj b/src/Volo.Abp.Identity.Application/Volo.Abp.Identity.Application.csproj index cc3af5858c..5dde635301 100644 --- a/src/Volo.Abp.Identity.Application/Volo.Abp.Identity.Application.csproj +++ b/src/Volo.Abp.Identity.Application/Volo.Abp.Identity.Application.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs new file mode 100644 index 0000000000..ec4ff20850 --- /dev/null +++ b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs @@ -0,0 +1,12 @@ +using AutoMapper; + +namespace Volo.Abp.Identity +{ + public class AbpIdentityApplicationModuleAutoMapperProfile : Profile + { + public AbpIdentityApplicationModuleAutoMapperProfile() + { + CreateMap(); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModule.cs b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModule.cs index dd4e11ba47..514f52ba74 100644 --- a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModule.cs +++ b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModule.cs @@ -1,14 +1,23 @@ using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; namespace Volo.Abp.Identity { - [DependsOn(typeof(AbpIdentityModule), typeof(AbpIdentityApplicationContractsModule))] + [DependsOn(typeof(AbpIdentityModule), typeof(AbpIdentityApplicationContractsModule), typeof(AbpAutoMapperModule))] public class AbpIdentityApplicationModule : AbpModule { public override void ConfigureServices(IServiceCollection services) { services.AddAssemblyOf(); + + services.Configure(options => + { + options.Configurators.Add(context => + { + context.MapperConfiguration.AddProfile(); + }); + }); } } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/UserAppService.cs b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/UserAppService.cs index e7f1f68800..9cd3161cd2 100644 --- a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/UserAppService.cs +++ b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/UserAppService.cs @@ -1,13 +1,14 @@ using System; -using System.Linq; +using System.Collections.Generic; using System.Threading.Tasks; +using Volo.Abp.Application.Services; using Volo.Abp.Application.Services.Dtos; namespace Volo.Abp.Identity { //TODO: Consider a way of passing cancellation token to all async application service methods! - public class UserAppService : IUserAppService + public class UserAppService : ApplicationService, IUserAppService { private readonly IIdentityUserRepository _userRepository; @@ -18,28 +19,18 @@ namespace Volo.Abp.Identity public async Task> GetAll() { - var users = (await _userRepository.GetListAsync()) - .Select(u => new IdentityUserDto - { - Id = u.Id, - Email = u.Email, - UserName = u.UserName - }) - .ToList(); + var users = await _userRepository.GetListAsync(); - return new ListResultDto(users); + return new ListResultDto( + ObjectMapper.Map, List>(users) + ); } public async Task Get(Guid id) { var user = await _userRepository.GetAsync(id); - return new IdentityUserDto - { - Id = user.Id, - UserName = user.UserName, - Email = user.Email - }; + return ObjectMapper.Map(user); } } } diff --git a/src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs b/src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs new file mode 100644 index 0000000000..e9ff2ac868 --- /dev/null +++ b/src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs @@ -0,0 +1,9 @@ +using Volo.Abp.ObjectMapping; + +namespace Volo.Abp.Application.Services +{ + public abstract class ApplicationService : IApplicationService + { + public IObjectMapper ObjectMapper { get; set; } + } +} \ No newline at end of file