2

i know you can do this

Mapper.CreateMap<Source, Dest>()
    .ForMember(d => d.Foo, opt => opt.ResolveUsing(res => res.Context.Options.Items["Foo"])

Mapper.Map<Source, Dest>(src, opt => opt.Items["Foo"] = "Bar");

but how do you access contextual data in AfterMap() ?

2
  • What do you mean saying contextual data? Can you give an example? Commented Apr 26, 2016 at 14:04
  • look at my example code, i can pass "options" with contextual data in a dictionary --> Items["Foo"] = someValue, this allows me to pass contextual data when im converting Commented Apr 26, 2016 at 14:11

1 Answer 1

2

Right now you can't. But that's an easy fix, open a GitHub issue and we'll add it in (for BeforeMap and AfterMap).

Sign up to request clarification or add additional context in comments.

2 Comments

Did this ever get implemented? This would be tremendously useful for supporting multiple version of clients, ie: when you need to pass a request-specific "ClientVersion" which you may want to change the shape of the returned data after mapping. The MVC controllers would then need to pass this request-specific data to the mapper, which is otherwise unaware of request-specific data/headers/etc.
Thanks for implementing this (tested as of v6.1). AutoMapper is awesome! =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.