Sdl.Web.Tridion/Mapping/ModelBuilderPipeline.cs
/// <summary>
/// Creates a Strongly Typed Entity Model for a given DXA R2 Data Model.
/// </summary>
/// <param name="entityModelData">The DXA R2 Data Model.</param>
/// <param name="baseModelType">The base type for the Entity Model to build.</param>
/// <param name="localization">The context <see cref="ILocalization"/>.</param>
/// <returns>The strongly typed Entity Model. Will be of type <paramref name="baseModelType"/> or a subclass.</returns>
Creates a Strongly Typed Entity Model for a given DXA R2 Data Model.
Creates a Strongly Typed Entity Model for a given DXA R2 Data Model .
public static EntityModel CreateEntityModel(EntityModelData entityModelData, Type baseModelType, ILocalization localization)
        {                        
            using (new Tracer(entityModelData, localization))
            {
                EntityModel entityModel = null;               
                if (CacheRegions.IsViewModelCachingEnabled) 
                {
                    string key = $"{localization.Id}-{CalcHash(entityModelData)}";
                    EntityModel cachedEntityModel = SiteConfiguration.CacheProvider.GetOrAdd(
                       key,
                       CacheRegions.EntityModel,
                       () =>
                       {
                           entityModel = CreateEntityModelInternal(entityModelData, baseModelType, localization);
                           if (entityModel.IsVolatile || entityModel.HasNoCacheAttribute)
                           {
                               Log.Trace($"EntityModel with id={entityModelData.Id} MvcData={entityModel.MvcData} localization={localization.Id} was marked for no caching.");
                               entityModel.IsVolatile = true;
                               return null;
                           }
                           Log.Trace($"EntityModel with id={entityModelData.Id} MvcData={entityModel.MvcData} localization={localization.Id} was added to cache.");
                           return entityModel;
                       }
                       );
                    if (cachedEntityModel != null)
                    {
                        entityModel = (EntityModel)cachedEntityModel.DeepCopy();
                    }
                }
                else
                {
                    entityModel = CreateEntityModelInternal(entityModelData, baseModelType, localization);
                }
                return entityModel;
            }
        }
public static EntityModel CreateEntityModel ( EntityModelData entityModelData , Type baseModelType , ILocalization localization ) { using ( new Tracer ( entityModelData , localization ) ) { EntityModel entityModel = null ; if ( CacheRegions . IsViewModelCachingEnabled ) { string key = $" { localization . Id } - { CalcHash ( entityModelData ) } " ; EntityModel cachedEntityModel = SiteConfiguration . CacheProvider . GetOrAdd ( key , CacheRegions . EntityModel , ( ) => { entityModel = CreateEntityModelInternal ( entityModelData , baseModelType , localization ) ; if ( entityModel . IsVolatile || entityModel . HasNoCacheAttribute ) { Log . Trace ( $" EntityModel with id= { entityModelData . Id }  MvcData= { entityModel . MvcData }  localization= { localization . Id }  was marked for no caching. " ) ; entityModel . IsVolatile = true ; return null ; } Log . Trace ( $" EntityModel with id= { entityModelData . Id }  MvcData= { entityModel . MvcData }  localization= { localization . Id }  was added to cache. " ) ; return entityModel ; } ) ; if ( cachedEntityModel != null ) { entityModel = ( EntityModel ) cachedEntityModel . DeepCopy ( ) ; } } else { entityModel = CreateEntityModelInternal ( entityModelData , baseModelType , localization ) ; } return entityModel ; } }
Creates a Strongly Typed Entity Model for a given DXA R2 Data Model.
Creates a Strongly Typed Entity Model for a given DXA R2 Data Model .
// quick way to avoid all caching on viewmodels // this entity has been marked for no caching so we return null to prevent a cache write                          // don't return the cached Page Model itself, because we don't want dynamic logic to modify the cached state.
The strongly typed Entity Model. Will be of type  or a subclass.
The strongly typed Entity Model . Will be of type or a subclass .
entityModelData
EntityModelData
The DXA R2 Data Model.
The DXA R2 Data Model .
baseModelType
Type
The base type for the Entity Model to build.
The base type for the Entity Model to build .
localization
ILocalization
The context .
The context .