Non-static usage with Mapping inside Resolvers.

32 views
Skip to first unread message

chris.k...@gmail.com

unread,
Apr 13, 2016, 12:53:09 PM4/13/16
to AutoMapper-users
Maybe I am trying to over-think this, but I am trying to remove ALL static usages from my code and encountered one that I cant figure out:

I have a call:

                  .ForMember(dest => dest.Policies, x => x.ResolveUsing<LossRunInfoResolver>())


and when it hits the resolver it needs Mapper too:

protected override PolicyDto ResolveCore(LossRunInfo source)


        {


            if (source.PolicyWorldId == 1)


                return Mapper.Map<PolicyDto>(source.Policies);


            if (source.PolicyWorldId == 2)


                return Mapper.Map<PolicyDto>(source.MarketingSubmission);



            return new PolicyDto();


        }



I am using Autofac to do DI in all the normal places where I have Mapper.Map, but this seems to be in the setup and I am not sure how to get the Mapper Instance that Is resolving the parent map into this resolver.

Am I missing something, or is this an over-looked part of this static-> instanced change?

Jimmy Bogard

unread,
Apr 13, 2016, 1:15:38 PM4/13/16
to automapp...@googlegroups.com
There's a mapper instance in the ResolutionContext object, you can use that!
--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages