Skip to content

Map configuration

Umut Ozel edited this page Apr 19, 2017 · 11 revisions

MapConfiguration is the main class of BatMap, we will use it for registering, mapping and projection.

public MapConfiguration(DynamicMapping dynamicMapping = DynamicMapping.NotAllowed, 
                        bool preserveReferences = false)

public MapConfiguration(IExpressionProvider expressionProvider, 
                        DynamicMapping dynamicMapping = DynamicMapping.NotAllowed, 
                        bool preserveReferences = false)

MapConfiguration has 3 constructor parameters in total, we can call them options:

  • dynamicMapping: When MapConfiguration encounter with an un-registered type, it checks this option.

    • NotAllowed (default): Throws an InvalidOperationException
    • Map: Maps the object but does not cache generated MapDefinition
    • MapAndCache: Maps the object and caches the generated MapDefinition, so next Map will be faster for same types
  • preserveReferences: (default: false) Default behavior for reference preserving. preserveReferences is used to overcome circular dependencies in types. All Map methods also has this option, but as nullable, when that parameter is null, this default value will be used. When enabled, slightly different Map code is executed, which checks an internal cache first whenever an instance must be created. When object is not available from cache, it creates new instance and caches it.

  • expressionProvider: (default: single lazy instance of ExpressionProvider) IExpressionProvider interface is responsible for creating MemberBindingExpression for given two property. You can inject your own implementation or a class inheriting from ExpressionProvider class.

Mapper - Static API

For easier use, there is a static class called Mapper with an internal instance of MapConfiguration. Mapper class has most of the ability of MapConfiguration. The internal MapConfiguration is created like this:

new MapConfiguration(DynamicMapping.MapAndCache)

So, static API has these options:

  • dynamicMapping = DynamicMapping.MapAndCache
  • preserveReferences = false
  • expressionProvider = ExpressionProvider's default instance

Registration

Clone this wiki locally