Life Through a Lens – My Glass Mapper With Sitecore

So you are here because you are either using Glass Mapper or want to know more on how to, particularly on the Sitecore platform. This series will be attempting to relate the use of Glass Mapper to real-world scenario’s which I have encountered, problems I have solved, approaches and / or idea’s on how you could use Glass Mapper in your own Sitecore implementations.

This is the first post in a series that I intend to run looking specifically at my experience of Glass Mapper, starting with what it is, how I use it and some common issues and hopefully a bit on TDD with Glass Mapper on the Sitecore Platform.

I will focus more on the MVC implementation during the course of the series, but Glass Mapper is equally potent and simple to implement when using purely Webforms (though I feel it’s testing benefits are more limited).

I would not knock other ORMs in this space and I hope not to compare Glass to it’s alternatives during the course of this series.

What is Glass?

Glass Mapper is an object-relational mapping framework for Sitecore. For the lay-man, it is a way of mapping your Sitecore structures to POCO objects by convention. This means you can have your ‘Seo Information Template’ to a class / interface something like this:


public interface ISeoInformation
{
   string SeoTitle { get; set; }
   string MetaKeywords { get; set; }
   string MetaDescription { get; set; }
}

Why Glass?

There are a few ORM tools now available for Sitecore as it stands. There are several distinctions between them, and obviously several similarities. MY key goals when picking an ORM were as follows.

  • It must support multiple template inheritance.
  • Unit Testable
  • It must not code gen.
  • It must be easily configurable
  • If possible, it should not ‘colour’ the domain objects

How can I get it?
This is the simplest question on this post – NUGET IS YOUR FRIEND.

What are Glass Mapper’s Key Features?

In my opinion, Glass Mapper’s key features on Sitecore are as follows.

  • Unit Test-ability
  • Fluent / Attribute Mapping
  • Mapping to interface (this will be covered in a later post)
  • Great Support
  • Maturity
  • Wide user community
  • Lazy loading

Being one of the more widely used I also find that it’s easier to justify it’s use over some alternatives to existing development teams.

Why do I like Glass Mapper for Sitecore?

For me, there are a number of reasons I like Glass Mapper on the Sitecore platform. One of the biggest reasons for my like of Glass as a product is the documentation and great feedback I have had when engaging it’s developers (chiefly Michael Edwards) in solving issues, also with general questions around the product. Being open source I have also had quite a while spent digging around in the codebase to figure it out (some of which I hope to share during the course of these posts). I find also as a freelance resource, it’s easy to sell in one of the most widely used and known about products in a space than younger / less well known alternatives. I guess its like trying to sell in SimpleInjector over one of the bigger players (by which I mean Unity, Autofac, Windsor or StructureMap…. Please don’t get me started on Ninject).

What do I feel are Glass Mapper’s current barriers to market?
In my personal opinion, I have found that there seems to be 3 major concerns when it comes to adopting Glass Mapper in an organisation, I will try and explain my thoughts further on what I believe on these points.

  • Time to learn – like any framework
  • Support
  • It’s not owned by Sitecore – Embrace and extend, Don’t Fight the Framework and all that.

In my opinion (again, strictly my own) I can say this.

  • I personally, learned enough to get going with Glass Mapper on the Sitecore platform in under 2 hours. This was done in the previous version where the documentation was in my opinion not as good. There were of course longer term challenges as you find with any framework. But when you compare this to the time to learn Lucene / Solr, this is pretty small.
  • Again, personally – running a few open source projects myself, any kind of feedback is always HUGE, it give’s us the knowledge that what we are doing is worthwhile. In this regard, whenever I have had a question, issue or whatever, I have found that I either get a response or potential fix (usually through a nightly) in a time that would make some commercial providers ashamed, and therefore as a consumer, makes me happy.
  • Finally, personal opinion (in particular on the MVC implementation). I hugely prefer working with POCO’s in Razor, I like Glass’ implementation MVC of this better than Sitecore’s own MVC implementation. I guess I add to this that at present I believe that neither Sitecore MVC OR Glass MVC are really a true MVC implementation. Again, another story for another post. (I want to make it more MVC and have some idea’s :D)
  • Further to the previous point, I believe that Glass’ implementation is very ‘Sitecore’ it hooks into pipelines where appropriate, doesn’t abstract the framework too far that you can’t use the original objects and / or implementations.

What do I consider Glass Mapper’s current challenges?
I am sure these can all be addressed in their own way over time, but it’s how I personally see it right now.

  • Strong tie to Windsor from the vendors (though I would say this given my work on agnostic) 😉
  • Instantiation of interfaces can be tricky to deal with, in particular – null checking
  • Some ‘features’ are still a little hidden (though I know Glass is working hard at that)

Conclusion

In the next post I will describe my current Glass ‘Eco-System’ at a high level with a view to diving into a few key points in later posts.

Remember that this series is based on MY experience and MY opinions, I always welcome being challenged on these and hopefully I will learn some things along the way, so please feed back wherever you feel you can. In part II I will look at considerations in getting Glass Mapper installed in a solution and what you choose.

I invite you please to provide feedback 😀

Advertisements

2 thoughts on “Life Through a Lens – My Glass Mapper With Sitecore

  1. Nice article ‘m looking froward to following your series on this.

    Just a couple of observations/questions:

    I too find that its difficult to sell the advantages of using Glass, and it always seems to be “we don’t have time to fit it in to the solution”, so I spend my own time adding it in to a branch, not usually more than a day. Then its “well we need time to test it and we just don’t have the resource”.

    With regards to your comment on Windsor, I have noted that changing to another IoC should be straight forward, but I have not as yet build the courage to take a look.

    Finally from your Key Goals why must it not code gen ? and what do you mean by “Colour” the domain objects ?

  2. Pingback: Life Through A Lens – Component Parts | CardinalCore

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s