What I would really like is to be able to do something like this:
public class AutoMapperConfiguration
{
public void Configure()
{
Mapper.CreateMap<Book, BookViewModel>()
.ForMember(dest => dest.Discount,
opt =>
opt.ResolveUsing<BookDiscountResolver>().FromMember(src => src.Id));
}
}
public class BookToBookViewModelMapper :
IBookToBookViewModelMapper
{
private readonly ICalculateDiscountService
_calculateDiscountService;
public BookToBookViewModelMapper(ICalculateDiscountService
calculateDiscountService)
{
_calculateDiscountService = calculateDiscountService;
}
public BookViewModel Map(Book book)
{
// *** Notice the With() call here, this is what I would
like to be able to do (or something similar) ***
Mapper.With<ICalculateDiscountService>(_calculateDiscountService).Map(book);
}
}
public class BookDiscountResolver : ValueResolver<int, decimal>
{
private readonly ICalculateDiscountService
_calculateDiscountService;
public BookDiscountResolver(ICalculateDiscountService
calculateDiscountService)
{
_calculateDiscountService = calculateDiscountService;
}
public override decimal Resolve(int id)
{
return _calculateDiscountService.CalculateDiscount(id);
}
}
I'm still on the 1.0 version of AutoMapper, so maybe this is already
possible ... thoughts?
Jon
--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To post to this group, send email to automapp...@googlegroups.com.
To unsubscribe from this group, send email to automapper-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.