2
CastleWindsor로 AutoMapper 5.1.1을 등록하려고하는데, 정확히 어디에서 Mapper.Initialize()를 호출해야할지 모르겠습니다.캐슬 윈저에 AutoMapper 5.1.1 등록하기
AutoMapper 프로파일 :
namespace AutoMapper_DI.Mappings
{
public class WebMappingProfile : Profile
{
public WebMappingProfile()
{
CreateMap<Person, PersonDTO>();
}
}
}
성 윈저 등록 :
class MainInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<TypedFactoryFacility>();
container.Register(Component.For<IMapper>().UsingFactoryMethod(x =>
{
return new MapperConfiguration(c =>
{
c.AddProfile<WebMappingProfile>();
}).CreateMapper();
}));
container.Register(Component.For<MainClass>());
}
}
내가 사용할 때 내가 매퍼를 가지고 _mapper 다음 초기화되지 않은 예외 : 어떤 조언을위한
class MainClass
{
private readonly IMapper _mapper;
public MainClass(IMapper mapper)
{
_mapper = mapper;
}
public void Start()
{
Person p = new Person
{
Name = "Somebody",
Surname = "Nobody",
Birth = new DateTime(1984, 06, 18)
};
var personDTO = Mapper.Map<Person, PersonDTO>(p);
}
}
감사합니다.
맵퍼 구성을 별도로 생성하고이를 Component.For()에 대한 "인스턴스"로 등록하는 것이 고려해 봤습니까? 인스턴스 (매퍼); –
stuartd