I’ve just started to use AutoMapper in my MVC 3 project and I’m wondering how people here structure their projects when using it. I’ve created a MapManager which simply has a SetupMaps method that I call in global.asax to create the initial map configurations. I also need to use a ValueResolver for one of my mappings. For me, this particular ValueResolver will be needed in a couple of different places and will simply return a value from Article.GenerateSlug.
So my questions are:
- How do you manage the initial creation of all of your maps (
Mapper.CreateMap)? - Where do you put the classes for your
ValueResolvers in your project? Do you create subfolders under your Model folder or something else entirely?
Thanks for any help.
i won’t speak to question 2 as its really personal preference, but for 1 i generally use one or more
AutoMapper.Profileto hold all myMapper.CreateMapfor a specific purpose (domaintoviewmodel, etc).then i create a bootstrapper (
IInitializer) that configures the Mapper, adding all of my profiles.then in my global.asax i get all instances of
IInitializerand loop through them runningExecute().that’s my general strategy.
by request, here is the reflection implementation of the final step.