Automapper
(v5.1.1.0) と(v3.2.0.0)を使用していNinject
ます。私のプロファイルクラスは次のとおりです。
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 は次のとおりです。
Mapper.Initialize(cfg =>
{
cfg.AddProfile<ApplicationUserResponseProfile>(); // unable to configure
});
また、Ninject カーネルにバインドしようとしました。
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));
});
しかし、両方の方法でエラーが発生しました-
このオブジェクトにはパラメーターなしのコンストラクターが定義されていません
私を助けてください。AutoMapper
でプロファイル クラス (パラメーターを持つ) を構成できませんNinject
。この問題を解決する別の方法はありますか?