Comparing DI frameworks with Sitecore ReflectionUtil

As a follow up on my last post about IoC / DI containers and how to use the Sitecore API to perform inversion of control using ReflectionUtil, I’ve made a quick speed comparison of some common DI frameworks, Sitecores ReflectionUtil and the new keyword as the best case for how quick it is to instantiate an object. The results The table below shows how long time it took to resolve and instantiate 1000 instances of a type without using constructor or parameter injection and without any lifetime management. Ninject27.360421582498Unity2.73812495641971ReflectionUtil0.19632199878594Simple Injector0.0757655566157367new Keyword0.0386374153259534 I ran the test 10 times and the results that I show here are the median, ranking from worst in top to best in bottom. ...

April 21, 2015 · 2 min · alc

Simple IoC container using only the Sitecore API

Lately there has been a lot of discussions on twitter about using different third party frameworks for Inversion of Control using Dependency Injection in Sitecore solutions. The arguments in these discussions can be almost religious, either for or against using a specific third party IoC framework. There are two extremes, on one side the developers who have just found IoC and now evangelize it wonders to the world and then on the other side we have developers who are either scared of IoC or have seen the hell it is when IoC frameworks are misused. ...

April 7, 2015 · 5 min · alc
initpipeline

Global.asax events and Sitecore pipelines

At Pentia we always try not to change any files that ships in an out-of-the-box Sitecore installation. This makes upgrading easier and the solution code more transparent for developers. Sitecore ships with a standard Global.asax file and a lot of Sitecore developers choose to make changes directly in this to hook into application and session level events. For example see the tutorial code from Glass Sitecore Mapper here the Global.asax is used to set the glass context on the Application_Start event. ...

October 12, 2014 · 2 min · alc
nested hell

Nesting if statements

This post is not only about Sitecore development it is valid for any code written in almost any language. It is about making code easier to read. The post is somewhat subjective but I hope that all developers with an IQ higher than 80 will agree. Back in the days when I learned to write code I could end up writing something like this: public void SomeMethod(string args) { if (args != null) var something = args.Something; if (something != null) { var someResult = DoSomethingWithSomething(something); if (someResult != null) { IGotMyResult(someResult); } } } But what I was doing back then was actually turning things upside down, writing “stay with me” instead of saying no right away, making the code less readable for other developers. ...

January 12, 2014 · 2 min · alc

Using threshold warning limits in Sitecore

When working on an old Sitecore solution the log files are almost always completely spammed with different threshold warnings. 744 10:28:14 WARN Item threshold exceeded for web page. Items accessed: 2578. Threshold: 2000. Page URL: /xxxx.aspx 7672 10:28:15 WARN Item threshold exceeded for web page. Items accessed: 29145. Threshold: 2000. Page URL:xxxx.aspx 7672 10:28:15 WARN Memory threshold exceeded for web page. Memory used: 37813KB. Threshold: 35000KB. Page URL:xxxx.aspx This is of course if you have not changed the threshold warning limits in configuration or turned off the threshold warnings completely which is only possible from version 6.4. ...

January 8, 2014 · 3 min · alc
bestpractice

Should be Sitecore best practices

During my work at Pentia I often perform health checks of existing Sitecore solutions built by other Sitecore partners. The solutions vary a lot in both quality and age but there are a few things which I need to point out as missing in each and every report. It is like it is secret Sitecore features only known by a small group of privileged developers even though it is so extremely basic. ...

January 6, 2014 · 5 min · alc
Sitecore admin

Disable the Sitecore admin user

A basic Sitecore 1-0-1 security check is to see if the admin account still uses the standard password. It is commonly seen that sites go into production with the admin / b still working. A way to ensure this does not occur is simply to disable the admin account when building to release or other public facing configurations. Disable Sitecore admin user We first create a setting for toggling if the admin user should be disabled. ...

October 29, 2013 · 2 min · alc

Developing Sitecore sites using DMS Personalization rules

As a developer it can be a rough road to start developing with DMS. Where do I start? How do I build a site that is accommodating to DMS? These are tough questions. In this post I will give some simple pointers that should get you started quick and easy on the right path. DMS has a thousand different applications and features, but the one that I feel is most useful for us developers and the easiest to start with is the personalization rules. These rules give us freedom and a great way to separate responsibilities away from our web controls. ...

October 13, 2013 · 3 min · eok

A note about Sitecore pipelines

My two previous posts both contained implementations of custom processors for the httpRequestBegin pipeline. Just a quick explanation about their structure and some absolute best practices when implementing your own Sitecore pipeline processors. Check and exit fast Since the httpRequestBegin pipeline handles all requests it is extremely important to check the context for validity before continuing processing. If a simple check fails then exit the processor right away. Example public class MyCustomProcessor { public void Process(PipelineArgs args) { if (!IsContextValidForProcessor()) return; DoSomeOperation(); } } This rule applies for all pipeline processors, if the context is not valid for the operation exit immediately and let the rest of the pipeline continue on. ...

October 13, 2013 · 2 min · alc