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 479295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:46:42+00:00 2026-05-13T00:46:42+00:00

I am configuring Automapper in the Bootstrapper and I call the Bootstrap() in the

  • 0

I am configuring Automapper in the Bootstrapper and I call the Bootstrap() in the Application_Start(), and I’ve been told that this is wrong because I have to modify my Bootstrapper class each time I have to add a new mapping, so I am violating the Open-Closed Principle.

How do you think, do I really violate this principle?

public static class Bootstrapper
{
    public static void BootStrap()
    {
        ModelBinders.Binders.DefaultBinder = new MyModelBinder();
        InputBuilder.BootStrap();
        ConfigureAutoMapper();
    }

    public static void ConfigureAutoMapper()
    {
        Mapper.CreateMap<User, UserDisplay>()
            .ForMember(o => o.UserRolesDescription,
                       opt => opt.ResolveUsing<RoleValueResolver>());
        Mapper.CreateMap<Organisation, OrganisationDisplay>();
        Mapper.CreateMap<Organisation, OrganisationOpenDisplay>();
        Mapper.CreateMap<OrganisationAddress, OrganisationAddressDisplay>();
    }    
}
  • 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-13T00:46:42+00:00Added an answer on May 13, 2026 at 12:46 am

    I would argue that you are violating two principles: the single responsibility principle (SRP) and the open/closed principle (OCP).

    You are violating the SRP because the bootstrapping class have more than one reason to change: if you alter model binding or the auto mapper configuration.

    You would be violating the OCP if you were to add additional bootstrapping code for configuring another sub-component of the system.

    How I usually handle this is that I define the following interface.

    public interface IGlobalConfiguration
    {
        void Configure();
    }
    

    For each component in the system that needs bootstrapping I would create a class that implements that interface.

    public class AutoMapperGlobalConfiguration : IGlobalConfiguration
    {
        private readonly IConfiguration configuration;
    
        public AutoMapperGlobalConfiguration(IConfiguration configuration)
        {
            this.configuration = configuration;
        }
    
        public void Configure()
        {
            // Add AutoMapper configuration here.
        }
    }
    
    public class ModelBindersGlobalConfiguration : IGlobalConfiguration
    {
        private readonly ModelBinderDictionary binders;
    
        public ModelBindersGlobalConfiguration(ModelBinderDictionary binders)
        {
            this.binders = binders;
        }
    
        public void Configure()
        {
            // Add model binding configuration here.
        }
    }
    

    I use Ninject to inject the dependencies. IConfiguration is the underlying implementation of the static AutoMapper class and ModelBinderDictionary is the ModelBinders.Binder object. I would then define a NinjectModule that would scan the specified assembly for any class that implements the IGlobalConfiguration interface and add those classes to a composite.

    public class GlobalConfigurationModule : NinjectModule
    {
        private readonly Assembly assembly;
    
        public GlobalConfigurationModule() 
            : this(Assembly.GetExecutingAssembly()) { }
    
        public GlobalConfigurationModule(Assembly assembly)
        {
            this.assembly = assembly;
        }
    
        public override void Load()
        {
            GlobalConfigurationComposite composite = 
                new GlobalConfigurationComposite();
    
            IEnumerable<Type> types = 
                assembly.GetExportedTypes().GetTypeOf<IGlobalConfiguration>()
                    .SkipAnyTypeOf<IComposite<IGlobalConfiguration>>();
    
            foreach (var type in types)
            {
                IGlobalConfiguration configuration = 
                    (IGlobalConfiguration)Kernel.Get(type);
                composite.Add(configuration);
            }
    
            Bind<IGlobalConfiguration>().ToConstant(composite);
        }
    }
    

    I would then add the following code to the Global.asax file.

    public class MvcApplication : HttpApplication
    {
        public void Application_Start()
        {
            IKernel kernel = new StandardKernel(
                new AutoMapperModule(),
                new MvcModule(),
                new GlobalConfigurationModule()
            );
    
            Kernel.Get<IGlobalConfiguration>().Configure();
        }
    }
    

    Now my bootstrapping code adheres to both SRP and OCP. I can easily add additional bootstrapping code by creating a class that implements the IGlobalConfiguration interface and my global configuration classes only have one reason to change.

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

Sidebar

Related Questions

I followed this tutorial on configuring the Rails plugin ExceptionNotifier. I know that I
I am configuring a new environment to run several intranet web applications. I have
I've been trying to use AutoMapper to save some time going from my DTOs
Configuring the PHP debuggers was so hard that I can't even imagine myself using
When configuring nginx with a site that has ssl, the examples I find online
I've been configuring LAMP server on Fedora core 13 and when I tr to
I have always used Visual Studios built in GUI support for configuring my projects,
I face many times this simple and repetitive task configuring the LAMP or some
i have placed a SqlDataSource component on my aspx page but while configuring the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.