Accessing ModelMapper

Constellation.Foundation.ModelMapping supports the Dependency Injection of IModelMapper. In your controllers, inject an instance of ModelMapper as follows:

public ControllerName(IModelMapper modelMapper)

The default implementation of IModelMapper is the ModelMapper class. You are free to override or mock this class by registering a different service with your Dependency Injection framework.

IModelMapper Methods

IModelMapper.MapTo(Item item, object model)

This is the core method used by all other interfaces described here.

Returns void

Iterates through the provided Item’s Fields, and if a public property of the object is found that matches the name of the field, an attempt is made to map the Field’s value to the property.

Properties can be ignored, and the exact mapping method used can be controlled through the use of Attributes decorating the target Property.

IModelMapper.MapItemToNew(Item item)

T must be a class with a parameterless constructor.

Returns an instance of T

Creates an instance of T and then calls MapTo(item, model) using the new instance of T as the model parameter.

IModelMapper.MapToCollectionOf<T>(ICollection items)

Item[], ChildList and any other ICollection are supported.

T must be a class with a parameterless constructor.

Returns an instance of ICollection<T>

For each member of the supplied list of Items, creates a new instance of T , maps the current Item to it, and appends the new object to the result list.

IModelMapper.MapToEnumerableOf<T>(IEnumerable items)

Item[], ChildList and any other IEnumerable are supported.

T must be a class with a parameterless constructor.

Returns an instance of IEnumerable<T>

For each member of the supplied list of Items, creates a new instance of T, maps the current Item to it, and appends the new object to the result list.