This project is read-only.

What is the best way to setup global configurations or profiles?

Mar 30, 2010 at 5:33 PM
Edited Mar 30, 2010 at 5:34 PM

Although I respect the power to be able to configure a mapping at any given moment, I would really like to have some standards that I setup once for the default instance. For example, I may want to standardize how DateTime is formatted when converting to string. Therefore, I have a global mapping configurator (an instance of DefaultMapConfig) stored in my wrapper class. It is initialized once with ConvertUsing, NullSubstitution, etc. calls. Whenever a map is requested, this configurator is used to get the mapper. Is this the recommended approach for such a setup?

May 20, 2012 at 6:50 AM

Were you able to figure out how to do it?

May 20, 2012 at 1:43 PM

I solved it using different instances of the ObjectMapperManager, having the burden of creating them.

If anyone has a better solution, any suggestion is welcome.

Aug 17, 2012 at 3:44 PM

EmitMapper author answers in this thread

(Google translation :)

>And it is already available. There is a default configurator - class DefaultMapConfig. This class encapsulates all the rules mapping. You can create one or several global instances of this class and use them when necessary:

public class Program
    public static IMappingConfigurator config1;
    public static IMappingConfigurator config2;

    static Program()
        config1 = new DefaultMapConfig()
            .MatchMembers((m1, m2) => m1.ToLower() == m2.ToLower()) // ignore case of field names
            .NullSubstitution<object, int>(state => 42) // all nulls will be int 42

        config2 = new DefaultMapConfig()
            .NullSubstitution<object, object>(state => DBNull.Value) // all nulls will be DBNull.Value
    public void Foo()
        var dest = ObjectsMapperManager.DefaultInstance.GetMapper<Source, Destination>(config1).Map(source);

In addition, there is a global default configuration, which is used by default. This configuration is available through "DefaultMapConfig.Instance" and it also can be changed and thus the behavior will change globally.

DefaultMapConfig.Instance.MatchMembers((m1, m2) => m1.ToLower() == m2.ToLower());
 ... dest = ObjectsMapperManager.DefaultInstance.GetMapper<Source, Destination>().Map(source);