TIHIDI: Glass Mapper with Custom Models and Mapping using Fluent Configuration

This blog post will go through how I setup Glass Mapper Models. I hand code models and also keep them close to a .NET Class/Interface. I setup a mapping project which will do the mapping of the custom model with Glass. I believe a cleaner and smaller View Model is the way to go. Some times you might need the entire template but most of the time its pieces of the template you need.

Visit http://www.glass.lu/mapper/sc for more information on Glass Mapper for Sitecore.

TIHIDI: Stands for This Is How I Do It. I am going to write a series of blog posts going through how I do Sitecore related work. Hope it helps you!

For all the fruit cakes who want to jump all over this, calm down. This is just a sample intended to showcase the mapping portion of it. This is not meant as a Sitecore or best practices example, although I am mindful of that.

Before I setup any models I setup an IGlassBase interface I use based on the need.

Lets setup a few models and their mappings. For pure auto maps, I dump all auto maps in one file PureAutoMaps.cs.






If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).


  • Dylan 1 year ago

    Don’t you need to define the fluent api mappings in the glassmappersc.cs file in order to tell glass what mappings to use? I didn’t see that included in this?

    Also I assume with the use of a fluent api, that you aren’t generating glass models using tds and their t4 templates? Is that because you don’t have tds or more that you prefer using the fluent api and/or customizing your poco models yourself?

  • akshaysuraadmin 1 year ago


    This is part of the TIHIDI series. If you see the last post: http://www.akshaysura.com/2016/07/21/tihidi-install-and-configure-glass-mapper-4-x-for-sitecore-8-x-mvc-solution-with-simple-injector-3-x/ the registrations for the mapping are in GlassMapperSCCustom.cs.

    I do have access to TDS but I like hand coding my models. Especially when we get into View Model’s where I only need specific fields from a template and not all the fields.

Add your comment

Your email address will not be published.