Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.


Interfaces

The following gives a draft of the interfaces required related to Model Binding. For convenience C# syntax is used.

Code Block
languagec#
public interface IModelBinder
{
    //We know upfront the type we want to bind to (IContextData is some kind of helper interface for processing the raw JSON)
    T BindPage<T>(IContextData data) where T: IPage;
    //Allow the type to bind to be determined by the context (eg page template) (note this is not the DD4T IPage)
	IPage BindPage(IContextData data);
    
    //We know upfront the type we want to bind to
    T BindEntity<T>(IContextData data) where T: IEntity;
	//Allow the type to be determined by the context (eg component template/schema)
    IEntity BindEntity(IContextData data);
}

Default Implementations

The following gives a draft of the default implementations; base classes which have virtual methods can be extended to alter model binding behaviour

Code Block
languagec#
public class DefaultModelBinder : IModelBinder
{
    /* -- IModelBinder implementation not added --*/


	//Can be overridden to apply specific property binding implementation
	protected virtual void BindProperty(object Model, PropertyDescriptor propertyDescriptor, IContextData contextData);
}

Attributes/Annotations

The following gives a draft of all the supported attributes/annotations related to Model Binding:

TODO