1
Automapper
(v5.1.1.0) 및 Ninject
(v3.2.0.0)을 사용 중입니다.매개 변수 생성자 및 Ninject로 Automapper 프로필 클래스 구성
public class ApplicationUserResponseProfile : Profile
{
public ApplicationUserResponseProfile(HttpRequestMessage httpRequestMessage)
{
UrlHelper urlHelper = new UrlHelper(httpRequestMessage);
CreateMap<ApplicationUser, ApplicationUserResponseModel>()
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => urlHelper.Link("GetUserById", new { id = src.Id })));
}
public ApplicationUserResponseModel Create(ApplicationUser applicationUser)
{
return Mapper.Map<ApplicationUserResponseModel>(applicationUser);
}
}
그리고 AutoMapperWebConfiguration은 다음과 같습니다 : 내 프로필 클래스입니다
var config = new MapperConfiguration(
c =>
{
c.AddProfile(typeof(ApplicationUserResponseProfile));
});
var mapper = config.CreateMapper();
kernel.Bind<IMapper>().ToConstant(mapper);
그리고 다른 방법 :
Mapper.Initialize(cfg =>
{
cfg.ConstructServicesUsing((type) => kernel.Get(type));
cfg.AddProfile(typeof(ApplicationUserResponseProfile));
});
Mapper.Initialize(cfg =>
{
cfg.AddProfile<ApplicationUserResponseProfile>(); // unable to configure
});
나는 또한 Ninject에 커널에 바인딩하기 위해 노력했다
하지만 e가 있습니다. 두 가지 방법으로 rror -이 객체 제발 도와주세요
에 대해 정의
없음 매개 변수가없는 생성자입니다.
Ninject
과 함께AutoMapper
프로필 클래스 (매개 변수가 있음)를 구성 할 수 없습니다. 이 문제를 해결할 다른 방법이 있습니까?