c# - Automapper 常用地图部分
问题描述
即我有以下地图类:
public class AutoMapperAddress : AutoMapper.Profile
{
public AutoMapperAddress()
{
CreateMap<AddressDto, ViewModels.AddressElementAPI>();
}
}
那么我应该在其他地方使用它,即:
public class AutoMapperLocation : AutoMapper.Profile
{
public AutoMapperLocation()
{
// location mappers here
// I need the same Address mapping as AutoMapperAddress has
}
}
public class AutoMapperCarrier : AutoMapper.Profile
{
public AutoMapperCarrier ()
{
// carrier mappers here
// I need the same Address mapping as AutoMapperAddress has
}
}
怎么做?
添加:
我试图在创建映射器对象期间解决它:
mapper = (new MapperConfiguration(cfg => {
cfg.AddProfile<Models.AutoMapperRules.AutoMapperLocation>();
cfg.AddProfile<Models.AutoMapperRules.AutoMapperAddress>();
}
)).CreateMapper();
但我想将它封装在 AutoMapperLocation 中,因为没有 AutoMapperAddress 就没有 AutoMapperLocation
解决方案
推荐阅读
- dynamic - Ecto:在每次迁移之前或之后运行 sql 脚本
- python - Python SQLITE3 Insert into and On conflict do update with variables - 语法问题?
- node.js - package.json 如何用多个 package.json 构建项目?
- c++ - 这个 C++ 函数在运行时会做什么?
- geolocation - ionic 5 @ionic-native/geolocation 添加提供者问题
- html - 在不改变父元素宽度的情况下替换一行上的两个 div
- java - 属性中的 Cedilla 不被读取
- google-chrome - Chrome 和 Firefox 之间的奇怪行为
- mysql - VB.NET MySQL:错误'无法将'System.Int32'类型的对象转换为'MySql.Data.MySqlClient.MySqlDataReader
- tensorflow - 运行 RNN-LSTM 时得到奇怪的准确度数字