I've been doing some performance stats on an ASP.NET 4.5 Webforms app, which seems a bit sluggish on initial startup after a fresh deployment.
One of the points I noticed is that creating the AutoMapper maps does take some time.
Since those maps are only used rather rarely, I was wondering if I could possibly "delay" creating those maps until the first time they're needed - sort of a "lazy initialization".
In that case, I would have to have some "non-destructive" (e.g. without throwing an exception) way of checking whether or not a given map exists - if there something like that in AutoMapper?
Thanks!
You can use FindTypeMapFor:
if (Mapper.FindTypeMapFor<TSource, TDestination>() == null)
Mapper.CreateMap<TSource, TDestination>();
// Map object
There's also an overload that takes type parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With