-
-
Save JasonMore/1036431 to your computer and use it in GitHub Desktop.
AutoMapperAssist example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mapper.CreateMap<TestClass, TestClassViewModel>() | |
.ForMember(dest => dest.Bar, opt => opt.MapFrom(src => src.Foo)); | |
var map = new Mapper<TestClass, TestClassViewModel>(Mapper.Engine); |
Interesting idea, I'll have to play around with resolving an IConfiguration from my IoC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, that's not a bad idea! It's actually why I created those constructors that accept a mapping engine or an AutoMapper IConfiguration instance: To make it possible to string these mappers together. You can still have a single instance of a configuration or a mapping engine, like you'd probably have using AutoMapper itself, but the mapping can still be executed behind these mappers.
If there's a "recommended" way to use AutoMapperAssist, it is to share the same IConfiguration object just like one would do with AutoMapper itself. I believe much of the cost of using AutoMapper is the CreateMap<> method, and if you use AutoMapperAssist's default constructor on the mapper, you'll pay that cost every time the mapper is instantiated. There are a number of ways to handle that, but the cleanest and simplest way might just be to load an instance of IConfiguration into your IoC container and let the mappers resolve from it.