Lassen Sie uns in Kontakt treten

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);

Lassen Sie uns in Kontakt treten

Geben Sie Ihre Daten ein um mit uns den Austausch zu beginnen.

Falls Sie ein alternatives Format und/oder Unterstützung bei der Kommunikation benötigen, wenden Sie sich bitte an Sheree Atcheson.