I have been meaning to extract out this solution for quite a while but never got time to do this. Even now I would like to publish a lot more code but unfortunately that is going to take a while!

I pushed an update to GitHub (https://github.com/akshaysura/sitecoremvc) with the initial code. It currently does not have any unit tests but I will be pushing another update shortly.

First I would like to thank Mike Edwards and Nathanael Mann for helping me jump start my Glass knowledge. I was able to pick up Glass in no time.

The purpose of this solution is to give you a baseline solution on Sitecore MVC implementation. I have been using a flavor of this for a year now on various projects and found it to be very useful and setup in a way that lends itself to reuse and test-ability.

Now a note to the snuggle bunnies who just see the negative in the world: when a guy posts Sitecore tips you do not find what is wrong with it, you acknowledge that fact that this person is sharing it his/her knowledge and if you have a better way of doing it, say so! It does not cost you any more to be nice! If you know of a way to make this better, share it.

On another note, share your knowledge, no point in safeguarding it! The more you share the better the community gets.

Now back to the solution. It is no surprise that I love Simple Injector, its my favorite. You can read all about it in the links below:

I found the combination of SimpleInjector, Glass4 and Sitecore MVC to be very stable and fast. In comparison we ran tests of 1000 active users, hitting the site at the rate of 635 requests per second, and the load being taken by two load balanced servers. The servers did not flinch and stayed at 35% CPU or below. This is a great example of how this can help you. Of course having good caching wouldn’t hurt!

I also tried out Kam’s Unicorn with Rainbow, I have to say that its fast and easy to configure. Best of all it was seamless which is what attracted me to try it out!

I plan on adding a lot more functionality in the coming weeks. The concepts in this solution are nothing new but how all of it is brought together might be interesting. Typically code isn’t shared in the Sitecore community when it comes to the actual building of the solution, but if its a module of course people are willing to freely share.

I am also going to include several examples of how to decouple Sitecore from a solution with real world examples. You are encouraged to pick and choose the code as you wish.

One thing to point out is the way Simple Injector is being initialized. Typically this can be done via Global.asax, WebActivatorEx and/or a Pipeline (the Sitecore way). I chose to do it the Sitecore way and initialize it via config and a pipeline.

XHTML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<?xml version="1.0"encoding="utf-8"?>

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"

xmlns:set="http://www.sitecore.net/xmlconfig/set/">

<sitecore>

<pipelines>

<initialize>

<!-- This could be done via global.asax, webactivatorex but doing it the Sitecore way -->

using Glass.Mapper.Sc;
using SimpleInjector;
using SimpleInjector.Packaging;
using SitecoreMVC.Business.Caching;
using SitecoreMVC.Business.Common;
using SitecoreMVC.Business.Metadata;
using SitecoreMVC.Business.Scripts;
using SitecoreMVC.Business.Shared;
using SitecoreMVC.Business.SitecoreSettings;
using SitecoreMVC.Models.TemplateModels;

Yes. Not able to paste the lines as it is. I am trying to register NotificationBarRepository with INotificationBarLogic(Custom Interface & Class) similar to that of MetaDataLogic, ScriptsLogic..etc(already Existing Interfaces).

This is a personal blog. Any views or opinions represented in this blog are my own and do not represent those of people, institutions or organizations that the I may or may not be associated with in professional or personal capacity including past, current and future employers, unless explicitly stated.