Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Current »

Overview

This page contains a draft definition of the functionality that would be required to related to binding CMS data to View Models.

Current Implementations

DXA uses a IModelBuilder interface as follows, IModelBuilders are chained together in a ModelBuilderPipeline, to allow additional processing to be done after the basic model is built from CMS data (this is for example how the model is enriched with data from SmartTarget queries)

public interface IModelBuilder
{
    void BuildPageModel(ref PageModel pageModel, IPage page, IEnumerable<IPage> includes, Localization localization);
    void BuildEntityModel(ref EntityModel entityModel, IComponentPresentation cp, Localization localization);
    void BuildEntityModel(ref EntityModel entityModel, IComponent component, Type baseModelType, Localization localization);
}

DD4T.NET

TODO 

DD4T.Java

TODO

Required Functionality

The View Models page contains an audit of existing DXA and DD4T functionality. This is distilled below into the following requirements table:

ReferencePriorityDescription
Model-1Must haveThe ModelBinder can bind Entity (Component Presentation) and Page Models from DD4T JSON
Model-2Must haveThe logic to determine the model Type from the source data should be extensible via an IModelTypeResolver
Model-3Must haveThere should be default IModelTypeResolvers to support existing DXA and DD4T logic - this will support the n→m mapping of schemas/component presentations to view models.
Model-4Nice to haveThe ModelBinder does not need to deserialize the source JSON into IPage or IComponentPresentation models before binding the view model
Model-5Must haveThe ModelBinder should be able to operate in isolation and thus independent from web application context and content provider. This also means there should be no dependencies on MVC classes or concepts.
Model-6Nice to haveThe ModelBinder has a test tool that can be used to test model binding without having to run the full Tridion and web application stack. This tool would take a set of DD4T JSON strings (for example a test set generated/copied from the CMS) and a library of model classes and show detailed binding logging and output checking which model properties are bound and to what source elements.
Region-1Must haveThe ModelBinder can resolve regions from the set of CPs on the page
Region-2Must haveThe logic for resolving regions is extensible using a IPageRegionResolver. The default behaviour is to resolve everything into a single region
Region-3Must haveA IPageRegionResolver which implements the DXA Region resolving logic will be provided
Link-1Must haveThe ModelBinder can resolve fields which are component links into URLs
Link-2Must haveThe logic for resolving links is extensible using an ILinkResolver
Link-3Must haveModel properties can be marked as 'dynamic' to prevent the link being resolved when the model is built
Link-4Must haveIt should be possible to bind a property to a resolved link to the source item (page or component)
Link-5Nice to haveLink resolving when binding a model can be done in bulk (once per model). Web8 architecture means that individual link resolving can result in a lot of http traffic. CIL contains a bulk linking facility which can be used to minimise this.
RTF-1Must haveThe ModelBinder can resolve Rich Text fields (resolving links and binaries)
RTF-2Must haveThe logic for resolving rich text is extensible using an IRichTextResolver
RTF-3Must haveAn implementation of the IRichTextResolver which implements the DXA Rich text resolving will be provided (splitting the RTF into a list of entities/html blocks)
Prop-1Must haveMultiple fields can be bound to the same model property. Attributes will be processed top-down until a source field is found to bind to the property
Prop-2Must haveA model property can be bound to a field within embedded schema(s) to enable 'Flatter' view models to be defined whose structure is not forced to correspond 1-1 to the source schema. This functionality will not extend to linked components however.
Prop-3Must haveFlattening should be optional and enabled on property, model and/or ModelBinder level
Prop-4Must haveA default, convention based binding should be implemented to allow for models without annotations/attributes to be used (map property names to schema field names using the DXA convention (PascalCase property to camelCase fieldname, drop a trailing s from enumerable properties (=multivalue fields) List<Paragraph> Paragraphs → paragraph field name)
Prop-5Must haveModel properties can be marked as ignored for binding purposes, and indeed at model level set that by default all properties without binding attributes are ignored. This allows for models whose data primarily comes from other sources to be efficiently bound.
Prop-6Must haveModel properties can be bound not just to field data, but also to system data (like Page/Component/Template Title, Id etc.
Prop-7Must haveModel properties can be bound to template metadata fields
Prop-8Must haveIt should be possible to map all source fields to a single property of Dictionary/Map type (DXA has this for configuration models)
Prop-9Must haveExtensible attributes (support what DD4T has)
Prop-10Nice to have

Model properties can be bound to arbitrary (ie not necessarily DD4T) JSON in the source data. This will allow custom JSON data to be injected into the DD4T JSON by templates which integrate with other content providers.




  • No labels