联系我们

How to set up AutoMapper in Sitecore

Sitecore Developer
Valtech

五月 10, 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);

联系我们

我們很樂意聽到您的聲音!請填寫表格,辦公室最近的人員將與您聯繫。
如果您需要其他格式和/或溝通支援來提供回饋,請聯絡Sheree Atcheson

让我们重新创造未来