I use the library automapperto convert mine Modelto my ViewModel. For each ModelI create a profile, inside which I add my cards using CreateMap.
I want to use a custom ValueResolverone in which it will get the registered user id from IContext, so I need to pass the implementation IContextusing Ninject.
Inside my profile class:
Mapper.CreateMap<ViewModel, BusinessModel>()
.ForMember(dest => dest.ManagerId, opt => opt.ResolveUsing<GetManagerResolver>());
Then mine GetManagerResolver:
public class GetManagerResolver : ValueResolver<BusinessModel, int>
{
private IContext context;
public GetManagerResolver(IContext context)
{
this.context = context;
}
protected override int GetManagerResolver(BusinessModel source)
{
return context.UserId;
}
}
But I get this exception message {"Type needs to have a constructor with 0 args or only optional args\r\nParameter name: type"}.
Any ideas on how to get automapper to use ninject to create an object?
UPDATE
My code for adding automapper configuration:
public static class AutoMapperWebConfiguration
{
public static void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile(new Profile1());
cfg.AddProfile(new Profile2());
});
}
}