Kontakt

How to set up AutoMapper in Sitecore

Sitecore Developer
Valtech

10. Mai 2019

How to reduce inefficiencies with AutoMapper for Sitecore

While working on one of our projects, I realized that every time developers needed to map a model (object) to another one, they had to copy each and every field from one object to another.

I looked for a solution to reduce this inefficiency, and realized that a very useful tool exists to accelerate the developers’ process. So, I introduced “AutoMapper” .Net Nuget Package to the team. I added the package, configured it, and used it in the solution.

Setting up Auto Mapper in Sitecore was easy, I just had to create a static object of type AutoMapper, and configure it to use the mapping profile, which was a class that contained all the models that needed to be mapped.

The following is a way of using AutoMapper:

 Mapping Profile:

CreateMap<GlobalSearch, GlobalSearchViewModel>();

Using the map:

Mapper.Map(workspaceFlyout, this);

Kontakt

Wir freuen uns auf Ihre Nachricht! Bitte füllen Sie das Formular aus. Der zuständige Mitarbeiter unseres Büros wird sich dann mit Ihnen in Verbindung setzen.
Sollten Sie ein alternatives Format und/oder Unterstützung bei der Kommunikation benötigen, um uns Feedback zu geben, wenden Sie sich bitte an Sheree Atcheson.

Let's reinvent the future