나는 이것에 관해 정말로 머리를 쓰고있다. Automapper 2.2.1에서 3.1.1로 업데이트했고 파산 전에 작동하던 코드가있었습니다. 실제 문제를 디버그하기 위해 더 많은 진단 정보를 얻으려고합니다.AssertConfigurationIsValid() 성공에도 불구하고 오토 맵퍼 매핑 예외
이public static class AutoMapperUnity
{
private static void Regsitrations()
{
Mapper.Reset();
var business = new BusinessLogicMaps(); business.Configure();
var api = new ApiServiceMaps(); api.Configure();
var wcf = new OldWcfMaps(); wcf.Configure();
Mapper.Configuration.AllowNullCollections = true;
}
public static void Registration(IUnityContainer container)
{
Regsitrations();
container.RegisterType<IMappingEngine>(new InjectionFactory(_ => Mapper.Engine));
container.RegisterType<IConfiguration>(new InjectionFactory(_ => Mapper.Configuration));
container.RegisterType<IConfigurationProvider>(new InjectionFactory(_ => Mapper.Configuration));
}
}
문제가 함께 발생 : 오류가
[TestClass]
public class TestOldWcfEndpoint
{
public TestContext TestContext { get; set; }
bool FieldWasSpecified;
[TestInitialize]
public void TestInitialize()
{
AutoMapperUnity.RegistrationInUnitTesting();
this.FieldWasSpecified = true;
}
[TestMethod]
public void Test_OldWcfHosting_AutomapperConfigurationIsValid()
{
try
{
AutoMapper.Mapper.AssertConfigurationIsValid();
}
catch (AutoMapper.AutoMapperMappingException aex)
{
this.TestContext.WriteLine(aex.Message);
throw;
}
}
}
AutoMapperUnity는 유니티 컨테이너에 묶을 수있는 정적 도우미 클래스입니다 존재하지 않기 때문에 단위 테스트에서
은 내가 패스를 wcf가 맵핑됩니다. Wcf 엔드 포인트는 웹 API 클라이언트가 사용하는 것과 동일한 DTO 계약에 따라 작성됩니다. Wcf 계약은 데이터 주석을 제외하고 완전히 동일합니다.public class OldWcfMaps
{
void CreateMapForCodes()
{
Mapper.CreateMap<CodeTypeDTO, CodeTypeWcfDTO>()
.ForMember(s => s.IDSpecified, o => o.Ignore());
Mapper.CreateMap<CodeTypeWcfDTO, CodeTypeDTO>();
Mapper.CreateMap<CodeDTO, CodeWcfDTO>()
.ForMember(s => s.ActiveSpecified, o => o.Ignore())
.ForMember(s => s.CodeTypeIDSpecified, o => o.Ignore())
.ForMember(s => s.IDSpecified, o => o.Ignore());
Mapper.CreateMap<CodeWcfDTO, CodeDTO>();
}
void CreateMapForCodeReports()
{
Mapper.CreateMap<CodeReportDTO, CodeReportWcfDTO>()
.ForMember(s => s.ActiveSpecified, o => o.Ignore())
.ForMember(s => s.AppIDSpecified, o => o.Ignore())
.ForMember(s => s.IDSpecified, o => o.Ignore())
.ForMember(s => s.CodeIDSpecified, o => o.Ignore())
Mapper.CreateMap<CodeReportWcfDTO, CodeReportDTO>();
}
void CreateMapForShiftReports()
{
this.CreateMapForCodeReports();
Mapper.CreateMap<ShiftReportDTO, ShiftReportWcfDTO>()
.ForMember(s => s.NumberOfReportsSpecified, o => o.Ignore());
Mapper.CreateMap<ShiftReportWcfDTO, ShiftReportDTO>();
}
public void Configure()
{
this.CreateMapForCodes();
this.CreateMapForShiftReports();
}
}
}
[ServiceBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class TimeClockServices : ITimeClockServices
{
/// <summary>
/// Reference to the AutoMapper Engine.
/// </summary>
private readonly IMappingEngine MapperEngine;
private readonly ILogFactory LogFactory;
private readonly ITimeClockDataService TimeClockApi;
public TimeClockServices(IMappingEngine mapper, ITimeClockDataService timeClockServices, ILogFactory logger)
{
this.MapperEngine = mapper;
this.TimeClockApi = timeClockServices;
this.LogFactory = logger;
}
public IEnumerable<CodeReportWcfDTO> GetCodeReports(ApplicationsEnum AppID, short DepartmentID, long CaseID, bool Active)
{
IEnumerable<CodeReportWcfDTO> groupOfWcfCodeReportDTOs = null;
try
{
// Get Data using shared internal interface.
IEnumerable<CodeReportDTO> codeReportDTOs =
this.TimeClockApi.GetCodeReports(AppID, DepartmentID, CaseID, Active);
// Convert the Data to the Wcf Extension Class.
// **OFFENDING LINE**
codeReportWcfDTOs =
this.MapperEngine.Map<IEnumerable<CodeReportDTO>, IEnumerable<CodeReportWcfDTO>>(codeReportDTOs);
}
catch (BLException bex)
{
throw new FaultException<BLExceptionFault>(
new BLExceptionFault("Business Engine Exception was thrown.", bex));
}
return codeReportWcfDTOs;
}
}
이 결국 오류에 이르게 :
Missing type map configuration or unsupported mapping.
Mapping types:
CodeReportDTO -> CodeReportWcfDTO
Api.Contract.Entities.CodeReportDTO -> Legacy.Contracts.WcfDTO.CodeReportWcfDTO
Destination path:
IEnumerable`1[0]
Source value:
Api.Contract.Entities.CodeReportDTO
을 내가 실제로 더 나은 문제 해결에 실패 모르는 바로 위의와 함께. 또한 DTO 계층은 동등한 Business Object에 맵핑됩니다.