Life Through A Lens – Common questions about adopting Glass Mapper

I often come across the same questions when looking at introducing Glass Mapper to a team and thought I would write a short post covering off some of the more common ones.

Why should I use Glass Mapper / What are the advantages & key features of Glass Mapper?

For me – the biggest advantages of Glass Mapper are as follows

  • A full read / write api (I believe it is still the only one)
  • Choice of configuration methods – Fluent, Attribute or Auto (Mapping generics are hopefully in the pipeline)
  • Unit testing – in particular the ability to test without too much mocking
  • Colouring of domain objects – I spoke about this before, but I like to (as close as possible) use raw .net types, not ORM specific ones.
  • Support
  • Maturity
  • Performance

You say Glass Mapper improves unit testing – how?

Show me the code!

I ran a quick user group session that touched on this a little last year – the source code still has a quick example of Unit tests using Glass Mapper.

The unit test is designed to ensure the Jobs returned for the Jobs Hub Page in my site are current vacancies and that it handles error conditions correctly (imagine the indexes aren’t built or they are locked / whatever). As you will see, there is minimal need to Mock objects, or replicate behaviour of the ORM, it is really very similar – in fact near identical to writing unit tests in raw .net. This is one of the biggest reasons I find Glass Mapper a joy to work with.

Does Glass Mapper have performance issues?
As you will see from the next question, the answer simply put is… no.

The site I was working on that triggered the investigation for Strategies to optimise Sitecore MVC Performance and Further Strategies to optimise Sitecore MVC Performance was actually running Glass Mapper. When I finished with all of the performance optimisation work, I ran a tests to find out how far off the level of performance the final site was compared to my vanilla test site.

On the test machine, the vanilla test site running @Html.Partial with ‘hello world’ renderings performed at 33,000 requests / minute (the fastest vanilla test). This did NOTHING except display ‘hello world’ 20 times. The final implementation of the target sites home page could manage 28,500 requests / minute – that’s with all of the images / lucene queries, personalisation, dynamic renderings etc etc.

Further to this, it has been my personal experience (with many hours of sitting in front of DotTrace / Ants Performance Profiler / Ants Memory Profiler), that to see any Glass Mapper methods even register is a rarity (bear in mind you can see methods as innocuous as object.ToString() for regular .net objects, so that’s saying something).

How much slower is Glass Mapper than Sitecore native?
There will be some statistics released on this at some point soon I understand, so I am not gonna give away too much, but I will say this much: Glass due it’s nature will always carry a small penalty in the fact it has to get items and map them to POCOs (measured in Ticks if I recall correctly), however complete with the presentation mechanisms compares favourably to native Sitecore methods.

How long does Glass Mapper take to set up?
In short – not much longer than Sitecore does 😀 – there is an awesome demonstration video on youtube from the fantastic Hedgehog Sitecore Virtual User Summit 2014 showing how quick & easy it really is. The documentation is improving all the time – particularly on the Glass Mapper website, and there is definitely going to be more effort to create some quick start material.

Is Glass Mapper hard to learn?

It was never my experience that this is the case. I think this in part is due to how I ‘expected’ the ORM to work aligning with how it did work. I started messing with Glass in v2 and watched the evolution and improvement into v3. It’s fairly evident to me that Glass has evolved through active use.

It does probably have a wider feature set than some ORM’s in the Sitecore space and some developers I guess have seen that as more of a curve, but to use it in its most basic form, I found it the easiest to get started with. I am always keen to find out the view’s of other developers that are using it.

Where can I find documentation?
I will beat Mike around the head with this later (mostly ’cause I had to find them again too!)- but there is a great set of Glass Mapper tutorials available. Obviously, I also cover some stuff on this blog too.

You could also consider purchasing training for Glass Mapper. There has been talk of a limited space training session around SUGCON 2015 – though this is as yet unconfirmed. For the cost, I think its a great introduction to the product and figure out how powerful it can really be. Needless to say, I will becoming a Glass Certified Developer as soon as the opportunity arises.

Glass Mapper ships with Castle Windsor, can I use different containers?
This has been much of a debate I have had with Glass. Needless to say, there are options. The official stand point is that Glass Mapper provides a supported Windsor implementation, if you want to use Glass, the simplest option is to use Glass using Windsor. There is nothing stopping you running Glass on Windsor and the rest of your application on SimpleInjector / AutoFac / StructureMap as I have done following my post on the impact of IoC container performance on Sitecore

  1. Glass Mapper on Agnostic IoC
  2. Glass Mapper provides a package that has nothing to do with Windsor. It is relatively simple to use the source code for the Windsor implementation as a base and write your own registrations based on your container of choice

However (after much feedback), expect to see some additional support for other containers (not using agnostic ioc) in future versions of Glass Mapper, along with other changes to the dependency registration process to better aid adding custom mappers and the like.

What’s the support like for Glass Mapper?
I have been following Glass Mapper since not that long after it’s initial releases, in that time I have gotten to know other folk who work with it as well as Mike Edwards and the other guys that have worked to make it the great product it is today. During this time, I have had support tickets / feature requests for the team. My experience from day one was that they actively monitor the issues on both Github / Stackoverflow and respond to email support requests very quickly.

I am hopeful that Glass Mapper will have more formal support agreement’s available in soon giving SLA’s to ensure working with the product is a smooth as possible, as I think this would be a selling point to bigger commercial enterprise as I have experience resistance to use open source software on these terms.

Does Glass Mapper work with Sitecore MVC?
Absolutely! in my (humble) opinion, it does so better than Sitecore does.

It’s worth noting that MVC’s key selling point for most developers was (and still should be) testability. In my opinion, Glass allows for easier testing on the Sitecore Experience Platform than any other method than I have seen to date.

How does Glass Mapper work with MVC?

Glass ships out of the box with an implementation that provides the Model as being the Datasource or the rendering or Context item (similar to how xslt renderings used to). This will be mapped to the provided class / interface according to the definition as provided in Sitecore. There are experiments going on to use the definition from the file – i.e. read the model type from the @inherits or whatever from the .cshtml. These are expected to drop in the next major release (the code works, just needs optimising).

After this, the majority of the time it’s EASIER to work with the GlassView class as it gives most of the functionality you would need straight off. Again, there are discussions around providing alternative methods for users who don’t want to do this, so please provide feedback of what you would like :D.

Do I have to use Glass Mapper’s presentation components to use Glass Mapper?
This has been a common misconception I have found. The short answer is… No.

Don’t get me wrong – its a ton easier for your MVC partials to inherit from Glass, but the IGlassHtml interface allows easy access to all of the functionality you need to render content mapped by Glass Mapper.

As always with my posts, I like to hear what you guys have to say. In particular with this one – I know the Glass Mapper team is looking all the time to introduce features people think it would benefit from and I would encourage the same for feeding back to any open source initiative you guys find helps your day job! (be it Unicorn, Glass, Synthesis, Fortis, Luke, Index Viewer or whatever)

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s