Skip to main content

Object Mapping

The ELEFLEX® platform uses the open source component AutoMapper for object to object mapping. By default, the standard naming conventions of objects within the various layers will use the same property names as each other. This is done so that when properties are added later, they use the same name within the various layered models and are then subsequently automatically mapped.

The platform provides a default mapping service, Eleflex.IMappingService which is used to provide dynamic object-to-object mapping and is used through the various application layers. Calling one of the various Map() methods and supplying a source object and optionally a destination object, will move data between the two. An internal startup task takes care of registering the default mapping provider during system startup (discussed in the next sections).

Integrators can register configurations for mapping by inheriting from the Eleflex.RegistrationTask object and adding the [MappingRegistrationTask] class attribute. The following examples demonstrates how to create a class used to register any object mapping configurations you define.

using Eleflex;
public partial class ExampleMappingRegistrationTask : RegistrationTask
       public ExampleMappingRegistrationTask()
            Description = "This tasks registers MyApp object mapping configurations.";
       public override bool Register(ITaskOptions taskOptions)
            AutoMapper.Mapper.CreateMap<MyApp.Model.EditPerson, MyApp.Model.Person>();
            AutoMapper.Mapper.CreateMap<MyApp.Model.Person, MyApp.Model.EditPerson>();
            return base.Register(taskOptions);

The next example shows how to map data between two objects using the Eleflex.IMappingService object.

//Use object locator to get mapping service
var mappingService = ObjectLocator.Current.GetInstance<Eleflex.IMappingService>();
MyApp.Model.EditPerson objA = new MyApp.Model.EditPerson();
objA.Name = “test”;

//Map Data Between Two Objects
MyApp.Model.Person objB = mappingService.Map<MyApp.Model.EditPerson,MyApp.Model.Person>(objA);