Browse Source

Migrate from AutoMapper to Mapperly in tenant management

Replaced AutoMapper usage with Mapperly in tenant management and MVC template modules. Removed obsolete AutoMapper mapping profile, updated project references and module dependencies, and refactored mapping configuration methods to use Mapperly.
pull/23623/head
Enis Necipoglu 1 year ago
parent
commit
54f773f18f
No known key found for this signature in database GPG Key ID: 1EC55E13241E1680
  1. 22
      modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMapperlyMappers.cs
  2. 36
      modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMappingProfile.cs
  3. 7
      modules/tenant-management/src/Volo.Abp.TenantManagement.Web/AbpTenantManagementWebMapperlyMappers.cs
  4. 2
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyCompanyName.MyProjectName.Mvc.csproj
  5. 19
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs

22
modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMapperlyMappers.cs

@ -7,34 +7,14 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.TenantManagement.Domain.Volo.Abp.TenantManagement;
[Mapper]
[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
public partial class TenantToTenantConfigurationMapper
: MapperBase<Tenant, TenantConfiguration>
{
[MapperIgnoreSource(nameof(Tenant.DeleterId))]
[MapperIgnoreSource(nameof(Tenant.DeletionTime))]
[MapperIgnoreSource(nameof(Tenant.LastModificationTime))]
[MapperIgnoreSource(nameof(Tenant.CreationTime))]
[MapperIgnoreSource(nameof(Tenant.CreatorId))]
[MapperIgnoreSource(nameof(Tenant.LastModifierId))]
[MapperIgnoreSource(nameof(Tenant.ExtraProperties))]
[MapperIgnoreSource(nameof(Tenant.ConcurrencyStamp))]
[MapperIgnoreSource(nameof(Tenant.IsDeleted))]
[MapperIgnoreSource(nameof(Tenant.EntityVersion))]
[MapperIgnoreTarget(nameof(TenantConfiguration.EditionId))]
[MapperIgnoreTarget(nameof(TenantConfiguration.IsActive))]
public override partial TenantConfiguration Map(Tenant source);
[MapperIgnoreSource(nameof(Tenant.DeleterId))]
[MapperIgnoreSource(nameof(Tenant.DeletionTime))]
[MapperIgnoreSource(nameof(Tenant.IsDeleted))]
[MapperIgnoreSource(nameof(Tenant.LastModificationTime))]
[MapperIgnoreSource(nameof(Tenant.LastModifierId))]
[MapperIgnoreSource(nameof(Tenant.CreationTime))]
[MapperIgnoreSource(nameof(Tenant.CreatorId))]
[MapperIgnoreSource(nameof(Tenant.ExtraProperties))]
[MapperIgnoreSource(nameof(Tenant.ConcurrencyStamp))]
[MapperIgnoreSource(nameof(Tenant.EntityVersion))]
[MapperIgnoreTarget(nameof(TenantConfiguration.EditionId))]
[MapperIgnoreTarget(nameof(TenantConfiguration.IsActive))]
public override partial void Map(Tenant source, TenantConfiguration destination);

36
modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMappingProfile.cs

@ -1,36 +0,0 @@
// using AutoMapper;
using Volo.Abp.Data;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.TenantManagement;
public class AbpTenantManagementDomainMappingProfile //: Profile
{
public AbpTenantManagementDomainMappingProfile()
{
// CreateMap<Tenant, TenantConfiguration>()
// .ForMember(ti => ti.ConnectionStrings, opts =>
// {
// opts.MapFrom((tenant, ti) =>
// {
// var connStrings = new ConnectionStrings();
// if (tenant.ConnectionStrings == null)
// {
// return connStrings;
// }
// foreach (var connectionString in tenant.ConnectionStrings)
// {
// connStrings[connectionString.Name] = connectionString.Value;
// }
// return connStrings;
// });
// })
// .ForMember(x => x.IsActive, x => x.Ignore())
// .ForMember(x => x.EditionId, x => x.Ignore());
// CreateMap<Tenant, TenantEto>();
}
}

7
modules/tenant-management/src/Volo.Abp.TenantManagement.Web/AbpTenantManagementWebMapperlyMappers.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Riok.Mapperly.Abstractions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Mapperly;
using Volo.Abp.TenantManagement.Web.Pages.TenantManagement.Tenants;
@ -19,7 +20,7 @@ public partial class TenantDtoToTenantInfoModelMapper
[Mapper]
public partial class TenantInfoModelToTenantCreateDtoMapper
: MapperBase<EditModalModel.TenantInfoModel, TenantCreateDto>
: TwoWayMapperBase<EditModalModel.TenantInfoModel, TenantCreateDto>
{
[MapperIgnoreSource(nameof(EditModalModel.TenantInfoModel.Id))]
[MapperIgnoreSource(nameof(EditModalModel.TenantInfoModel.ConcurrencyStamp))]
@ -32,6 +33,10 @@ public partial class TenantInfoModelToTenantCreateDtoMapper
[MapperIgnoreTarget(nameof(TenantCreateDto.AdminEmailAddress))]
[MapperIgnoreTarget(nameof(TenantCreateDto.AdminPassword))]
public override partial void Map(EditModalModel.TenantInfoModel source, TenantCreateDto destination);
public override partial EditModalModel.TenantInfoModel ReverseMap(TenantCreateDto source);
public override partial void ReverseMap(TenantCreateDto source, EditModalModel.TenantInfoModel destination);
}
[Mapper]

2
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyCompanyName.MyProjectName.Mvc.csproj

@ -23,7 +23,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Mapperly\Volo.Abp.Mapperly.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Swashbuckle\Volo.Abp.Swashbuckle.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Serilog\Volo.Abp.AspNetCore.Serilog.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EntityFrameworkCore.SqlServer\Volo.Abp.EntityFrameworkCore.SqlServer.csproj" />

19
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs

@ -18,7 +18,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
using Volo.Abp.Mapperly;
using Volo.Abp.Emailing;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
@ -57,7 +57,7 @@ namespace MyCompanyName.MyProjectName;
// ABP Framework packages
typeof(AbpAspNetCoreMvcModule),
typeof(AbpAutofacModule),
typeof(AbpAutoMapperModule),
typeof(AbpMapperlyModule),
typeof(AbpEntityFrameworkCoreSqlServerModule),
typeof(AbpSwashbuckleModule),
typeof(AbpAspNetCoreSerilogModule),
@ -162,7 +162,7 @@ public class MyProjectNameModule : AbpModule
ConfigureMultiTenancy();
ConfigureUrls(configuration);
ConfigureBundles();
ConfigureAutoMapper(context);
ConfigureMapperly(context);
ConfigureSwagger(context.Services);
ConfigureNavigationServices();
ConfigureAutoApiControllers();
@ -291,17 +291,10 @@ public class MyProjectNameModule : AbpModule
);
}
private void ConfigureAutoMapper(ServiceConfigurationContext context)
private void ConfigureMapperly(ServiceConfigurationContext context)
{
context.Services.AddAutoMapperObjectMapper<MyProjectNameModule>();
Configure<AbpAutoMapperOptions>(options =>
{
/* Uncomment `validate: true` if you want to enable the Configuration Validation feature.
* See AutoMapper's documentation to learn what it is:
* https://docs.automapper.org/en/stable/Configuration-validation.html
*/
options.AddMaps<MyProjectNameModule>(/* validate: true */);
});
context.Services.AddMapperlyObjectMapper();
context.Services.AddMapperlyObjectMapper<MyProjectNameModule>();
}
private void ConfigureEfCore(ServiceConfigurationContext context)

Loading…
Cancel
Save