Source code for this framework is available on GitHub
It’s been 3 year I have been working on Sitecore Mvc (6.6 & 7.2) and had seen some of the bad and best enterprise framework laid out for Sitecore development. With Sitecore it is really important to structure the solution correctly to facilitate development team to design a scalable solution and code without worrying about another part of the application. It is also important to develop individual components without any dependency on the functional or non functional part of the code.
This tempted me to write an abstract framework or layout the basic building block of the application which are required for any Sitecore Mvc development. I have found other frameworks available e.g Sitecore Mvc Contrib or Sample Sitecore Mvc but I haven’t used them so far.
It is not possible to cover all the feature in this post and it may require a series of post to cover it. Following are the feature included so far. I will turn them in links once I have the relevant post out.
- Pluggable Mvc Areas Implementation
- Form Post in Siteocre MVC
- Exception Handling
- Dependency Injection – Container agnostic
- Asynchronous Logging – Framework agnostic
- Integration with Claims Identity
- Glass Mapper Implementation
- Unit Testing
This Project is designed using Sitecore 7.2 and Mvc 5.1 and here is how it looks like from solution alignment point of view.
The key consideration here is to un-touch the Sitecore Host project and code outside of it using pluggable module, on build just deploy the required files in host project’s respective directories and run the application. This open up the idea of deploying individual component as separate module in Sitecore via xcopy, nuget package or any other deployment mechanism. It helps in environment where multiple teams are working independently.
Exception handling is designed to handle the application error via HttpModule and Mvc specific one with Sitecore’s Exception Processor. The important part of it is that it avoids the redirect and render the error page content along with correct error status code. Framework keeps the error handling simple but it doesn’t stop if there is a need for richer experience. I wrote about it long back here , this can be still applied to present more customized solution.
Dependency Injection is achieved via a Framework IoC class but it internally rely on a container which could be any container available, either Unity, Windsor or any other. This allows less dependency on the DI container and build application specific code. The current application uses Unity as sample implementation.
Logging implementation is asynchronous and it uses BackgroundWorker class to process log to consuming framework. The current implementation uses a simple file to write the log. It can be enhanced to use the new .net based async/await support or AsyncCollection for cleaner implementation.
The other major feature it supports is ClaimsIdentity over the existing IIdentity implementation for Claims based access. It allows access to User attributes in the runtime for more fine grain control over the user properties and access. This can further be extended to support Federation authentication within the application.
I haven’t added the full glass mapper example and unit testing yet but that’s in-progress.
How to setup
This solution is consist of 3 main module, 1) Framework 2) Modules (Mvc Areas) 3)Host Project
Framework is build with 4 projects
- Infrastructure- Infrastructure project contains dependency injection and Logging functionality.
- Sitecore Extension- This project contains extensions for Sitecore areas & error handling pipelines, support for ClaimsIdentity and some helper classes.
- Web Extension- Currently it has helper and extension classes to support Form Post.
- Setup- This project contains unity based DI implementation, file logger and application bootstrap to wire-up all project together without making any modification in Host project.
Module is nothing but collection of Mvc projects with area registration classes to support pluggable application development and it can be deployed to Host project as package.
Host is a Sitecore project and it works are integration point for Framework and pluggable Mvc modules.
- Download the source code for this article from GitHub and open the solution in Visual Studio 2013, you will notice it has all the projects available but host project doesn’t have much except, App_Config/Include/Framework for config file required by Framework, empty Areas folder, script and content folder for jquery and bootstrap css files.
- Download the Sitecore 7.2 from SDN.
- Copy below files/folder from Sitecore7.2 downloaded zip file to Host project directory.
- App_Config folder
- bin folder
- Layouts folder
- Sitecore folder
- Sitecore Modules folder
- Sitecore_files folder
- Temp folder
- Data folder with license file
- Upload folder
- xsl folder
Once everything is ready, build the solution and it should generate the required assembly inside the Host project’s bin folder to run the application.
This solution is still in development and not been used on any production environment. I am trying my best to test out all the aspect of framework but if you are planning to use this framework, let me know and I will try to help you set it up, just shoot me an email.
Any feedback, drop in the comment section or email me.