Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6186823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:57:17+00:00 2026-05-24T01:57:17+00:00

I’m using AutoMapper in an ASP.NET MVC application. I was told that I should

  • 0

I’m using AutoMapper in an ASP.NET MVC application. I was told that I should move the AutoMapper.CreateMap elsewhere as they have a lot of overhead. I’m not too sure how to design my application to put these calls in just 1 place.

I have a web layer, service layer and a data layer. Each a project of its own. I use Ninject to DI everything. I’ll utilize AutoMapper in both web and service layers.

So what are your setup for AutoMapper‘s CreateMap? Where do you put it? How do you call it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:57:17+00:00Added an answer on May 24, 2026 at 1:57 am

    Doesn’t matter, as long as it’s a static class. It’s all about convention.

    Our convention is that each “layer” (web, services, data) has a single file called AutoMapperXConfiguration.cs, with a single method called Configure(), where X is the layer.

    The Configure() method then calls private methods for each area.

    Here’s an example of our web tier config:

    public static class AutoMapperWebConfiguration
    {
       public static void Configure()
       {
          ConfigureUserMapping();
          ConfigurePostMapping();
       }
    
       private static void ConfigureUserMapping()
       {
          Mapper.CreateMap<User,UserViewModel>();
       } 
    
       // ... etc
    }
    

    We create a method for each “aggregate” (User, Post), so things are separated nicely.

    Then your Global.asax:

    AutoMapperWebConfiguration.Configure();
    AutoMapperServicesConfiguration.Configure();
    AutoMapperDomainConfiguration.Configure();
    // etc
    

    It’s kind of like an “interface of words” – can’t enforce it, but you expect it, so you can code (and refactor) if necessary.

    EDIT:

    Just thought I’d mention that I now use AutoMapper profiles, so the above example becomes:

    public static class AutoMapperWebConfiguration
    {
       public static void Configure()
       {
          Mapper.Initialize(cfg =>
          {
            cfg.AddProfile(new UserProfile());
            cfg.AddProfile(new PostProfile());
          });
       }
    }
    
    public class UserProfile : Profile
    {
        protected override void Configure()
        {
             Mapper.CreateMap<User,UserViewModel>();
        }
    }
    

    Much cleaner/more robust.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.