Constellation.Foundation.ModelMapping
Requires Sitecore 10.3 Requires .NET 4.8 Constellation is a collection of utilities for .NET CMS implementers. The Foundation.ModelMapping library is inspired by AutoMapper and is designed to provide a quick, non-ORM method of mapping Sitecore Items to ViewModels. String properties on your ViewModel will be mapped to FieldRendered values from fields with the same names. Integer and DateTime property types can also be handled automatically, although you will not get page editor support for these types. There are a number of Attributes that you can assign to your ViewModel's properties to change the behavior of the Mapper. Usage: var modelMapper = (IModelMapper)ServiceLocator.ServiceProvider.GetService(typeof(IModelMapper)); // Dependency Injection of an IModelMapper is supported TModel viewModel = modelMapper.MapItemToNew<TModel>(sourceItem); Or: TModel viewmodel = item.MapToNew<TModel>(); Or: modelMapper.MapTo(item, model); When using Item or ItemList extensions for mapping, the context IModelMapper is requested from the ServiceLocator, so any moc objects you use for testing are supported with these extension methods. Constraints: - Your ViewModel must have a public, parameterless constructor. - Only Writable, Public Instance properties will be mapped. - Within Sitecore, your field names can be human-legible. ModelMapper will attempt to convert the field name to a valid Property name. Simpler names work best. You can use the Field's Display Name for better human legibility and keep the Field's actual name closer to a legit C# entity name. - ViewModel properties can be: - - Strings - - HtmlStrings (recommended for RichText and FieldRenderer) - - Integers - - Decimals - - DateTimes - - Other ViewModels (recommended for DropLink, DropTree) - - ICollection Generics of other ViewModels (recommended for Multilist, Treelist) - - ModelMapping.Model.ImageModel (for Image Fields, gives access to all field properties and permits generating different kinds of image URLs on the View.) - - ModelMapping.Model.GeneralLinkModel (for General Link fields, gives access to all field properties through a single object.) - - Random Plain Old Classes as long as they are Where T: class, new() The following Model properties are mapped to Item properties rather than Item fields: - ID - Maps to the Item.ID - Make sure you use Sitecore.Data.ID as the property type. - Name - Maps to the Item.Name - DisplayName - Maps to Item.DisplayName - Url - Should be a string, not a Uri. Causes the current context LinkManager to generate a Url for the Item. - Parent - Maps to the ViewModel you provide based on the Item.Parent. Support for XML Field Attributes - ImageField.Alt - use Model.FieldNameAlt - ImageField.Height - use Model.FieldNameHeight - GeneralLink.Target - use Model.FieldNameTarget - etc. Support for LinkField.TargetItem - use Model.FieldNameTargetItem and supply a class with public properties and a parameterless constructor. Support for MultilistField.GetItems - use Model.FieldName and supply a generic ICollection<T> where "T" is new() and has properties you can map. Extensible! See the Constellation.Foundation.ModelMapping.config file to change the way Fields are processed.
Activity
- Latest release
- 3y ago
- Total releases
- 86
- Cadence
- ~8 days
- Last 12 months
- 0
Details
- License
- MIT
- First release
- Nov 29, 2017
| Version | Released | |
|---|---|---|
10.3.0.23496
minor
|
10.3.0.23496
minor
Dependencies (1)
|
|
10.2.7.23399
patch
|
10.2.7.23399
patch
Dependencies (3)
|
|
10.2.6.14185
patch
|
10.2.6.14185
patch
Dependencies (3)
|
|
10.2.5.29046
patch
|
10.2.5.29046
patch
Dependencies (3)
|
|
10.2.4.23594
patch
|
10.2.4.23594
patch
Dependencies (3)
|
|
10.2.3.22209
patch
|
10.2.3.22209
patch
Dependencies (3)
|
|
10.1.4.22077
patch
|
10.1.4.22077
patch
Dependencies (1)
|
|
10.2.2.20071
patch
|
10.2.2.20071
patch
Dependencies (3)
|
|
10.1.3.19919
patch
|
10.1.3.19919
patch
Dependencies (1)
|
|
10.2.1.25406
patch
|
10.2.1.25406
patch
Dependencies (3)
|
|
10.1.2.25254
patch
|
10.1.2.25254
patch
Dependencies (1)
|
|
10.2.0.30381
minor
|
10.2.0.30381
minor
Dependencies (3)
|
|
10.1.1.25245
patch
|
10.1.1.25245
patch
Dependencies (1)
|
|
10.1.0.29258
minor
|
10.1.0.29258
minor
Dependencies (1)
|
|
9.1.15.16445
patch
|
9.1.15.16445
patch
Dependencies (1)
|
|
9.3.2.16363
patch
|
9.3.2.16363
patch
Dependencies (1)
|
|
10.0.8.16246
patch
|
10.0.8.16246
patch
Dependencies (1)
|
|
10.0.7.20073
patch
|
10.0.7.20073
patch
Dependencies (1)
|
|
10.0.6.24075
patch
|
10.0.6.24075
patch
Dependencies (1)
|
|
10.0.5.32533
patch
|
10.0.5.32533
patch
Dependencies (1)
|
|
9.1.14.26346
patch
|
9.1.14.26346
patch
Dependencies (1)
|
|
9.3.1.26142
patch
|
9.3.1.26142
patch
Dependencies (1)
|
|
10.0.4.24372
patch
|
10.0.4.24372
patch
Dependencies (1)
|
|
9.1.13.23109
patch
|
9.1.13.23109
patch
Dependencies (1)
|
|
10.0.3.22928
patch
|
10.0.3.22928
patch
Dependencies (1)
|
|
9.1.12.19097
patch
|
9.1.12.19097
patch
Dependencies (1)
|
|
10.0.2.24237
patch
|
10.0.2.24237
patch
Dependencies (1)
|
|
10.0.1.23906
patch
|
10.0.1.23906
patch
Dependencies (1)
|
|
10.0.0.23188
major
|
10.0.0.23188
major
Dependencies (1)
|
|
9.3.0.29450
minor
|
9.3.0.29450
minor
Dependencies (1)
|
|
8.1.3.19984
patch
|
8.1.3.19984
patch
Dependencies (2)
|
|
8.1.3.19261
initial
|
8.1.3.19261
initial
Dependencies (2)
|
|
9.1.11.16238
patch
|
9.1.11.16238
patch
Dependencies (1)
|
|
9.1.10.19264
patch
|
9.1.10.19264
patch
Dependencies (1)
|
|
9.1.9.30419
patch
|
9.1.9.30419
patch
Dependencies (1)
|
|
9.1.8.25631
patch
|
9.1.8.25631
patch
Dependencies (1)
|
|
9.1.7.27091
patch
|
9.1.7.27091
patch
Dependencies (1)
|
|
9.1.6.15984
patch
|
9.1.6.15984
patch
Dependencies (1)
|
|
9.1.5.27908
patch
|
9.1.5.27908
patch
Dependencies (1)
|
|
9.1.4.28433
patch
|
9.1.4.28433
patch
Dependencies (1)
|
|
9.1.3.23444
patch
|
9.1.3.23444
patch
Dependencies (1)
|
|
9.1.2.24353
patch
|
9.1.2.24353
patch
Dependencies (9)
+ 1 more |
|
9.1.1.23876
patch
|
9.1.1.23876
patch
Dependencies (7)
|
|
9.1.0.16301
minor
|
9.1.0.16301
minor
Dependencies (7)
|
|
9.0.33.27934
patch
|
9.0.33.27934
patch
Dependencies (2)
|
|
9.0.32.25356
patch
|
9.0.32.25356
patch
Dependencies (2)
|
|
9.0.31.30043
patch
|
9.0.31.30043
patch
Dependencies (2)
|
|
9.0.30.20651
patch
|
9.0.30.20651
patch
Dependencies (2)
|
|
9.0.30.16759
patch
|
9.0.30.16759
patch
Dependencies (2)
|
|
9.0.29.16036
patch
|
9.0.29.16036
patch
Dependencies (1)
|