Skip to content

Commit f3245e2

Browse files
eshanrnhgitbook-bot
authored andcommitted
GITBOOK-38: Updated info note in Umbraco Mapper article
1 parent da4c428 commit f3245e2

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

15/umbraco-cms/reference/mapping.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ Often in code there is a need to 'map' one object's properties to another type o
55
{% hint style="info" %}
66
UmbracoMapper replaced AutoMapper which was an external dependency. AutoMapper builds the mapping code dynamically, based upon mapping profiles, which are defined as C# expressions. UmbracoMapper relies on static code, that is, mappings need to be hand-written.
77

8-
This is not to be confused with the [UmbracoMapper package by Andy Butland](https://our.umbraco.com/packages/developer-tools/umbraco-mapper) of the same name.
8+
If you need to map `IPublishedContent`, you might need a **custom implementation** or a **third-party solution like** [**Andy Butland’s Umbraco Mapper**](https://our.umbraco.com/packages/developer-tools/umbraco-mapper) **(**which has been renamed to [Anaximapper](https://www.andybutland.dev/2022/08/a-quick-post-on-view-model-mapping.html)) rather than relying on Umbraco's `IUmbracoMapper.`
99
{% endhint %}
1010

11-
UmbracoMapper was originally introduced to solve some issues in the Umbraco core code. However, it is fine for anyone to use in their custom site implementations or packages as they wish.
12-
1311
## Accessing the IUmbracoMapper
1412

1513
The IUmbracoMapper is registered with Dependency Injection (DI). It can therefore be injected into constructors of controllers, custom classes etc, wherever DI is used.
@@ -90,22 +88,21 @@ The mapping action is used to map an instance of the source class, to an instanc
9088

9189
The constructor function is used whenever the mapper is asked to create a target instance. Then, the mapping action is used.
9290

93-
In other words, `umbracoMapper.Map<ITarget>(source)` will first run the construction function, and then the mapping action.
94-
On the other hand, `umbracoMapper.Map(source, target)` where target already exists, would only run the mapping action.
91+
In other words, `umbracoMapper.Map<ITarget>(source)` will first run the construction function, and then the mapping action. On the other hand, `umbracoMapper.Map(source, target)` where target already exists, would only run the mapping action.
9592

9693
The UmbracoMapper class provides multiple overloads of the Define method:
9794

98-
- An overload accepting a constructor function and a mapping action, as presented above.
99-
- An overload accepting a mapping action only, which tells the mapper how to map to an existing target (but the mapper will not be able to create new target instances).
100-
- An overload accepting a construction function, which tells the mapper how to create new target instances (but the mapper will not perform any additional mapping).
101-
- A parameter-less overload, which defines a "no-operation" mapping (the mapper cannot create new target instance, and mapping does nothing).
95+
* An overload accepting a constructor function and a mapping action, as presented above.
96+
* An overload accepting a mapping action only, which tells the mapper how to map to an existing target (but the mapper will not be able to create new target instances).
97+
* An overload accepting a construction function, which tells the mapper how to create new target instances (but the mapper will not perform any additional mapping).
98+
* A parameter-less overload, which defines a "no-operation" mapping (the mapper cannot create new target instance, and mapping does nothing).
10299

103100
## Context
104101

105102
Both constructor functions and map actions presented above expose a context parameter which is an instance of MapperContext and provides two types of services:
106103

107-
- An `Items` dictionary which can store any type of object, using string keys, and can be used to carry some context along mappings;
108-
- Some Map and MapEnumerable functions that can be used in mapping functions, to recursively map nested elements, while propagating the context.
104+
* An `Items` dictionary which can store any type of object, using string keys, and can be used to carry some context along mappings;
105+
* Some Map and MapEnumerable functions that can be used in mapping functions, to recursively map nested elements, while propagating the context.
109106

110107
{% hint style="info" %}
111108
The context provides a `HasItem` property. To check whether the context has items, without allocating an extra empty dictionary, use this property.

0 commit comments

Comments
 (0)