Developer Isolation – the mushroom cupboard should see the greenhouse

A slightly strange title, but let me explain. First of all – it’s possibly self evident, but for those who don’t see it – developers in so many industries are treated similar to mushrooms – keep them sustained in a dark room and they will produce useful material. On the other hand – we have marketers / designers / project managers. The former two of which are (and rightly so in many instances) considered to be the driving forces in their field and thus are exposed to the sun (the clients / world) by virtue of glass walls & ceilings.

I have for many many years been both a developer and a social person. I enjoy interacting with clients / fellow developers & others – be them from media agencies or ‘end’ clients (ie: Sitecore Customers) and I have found distinct differences between the way different organisations interact with their own developers and (from a personal point of view) what I consider to be a disparity in how productive the developers can be directly linked to how close they are to the problem.

In this post I will explore why developers (mushrooms) should be allowed out to see the wider picture (greenhouse) more regularly.

Continue reading

Why TFS is the probably the worst choice for Sitecore

I haven’t posted in a while, but recent projects got me thinking. I have had the opportunity to work in many environments with a range of tooling and processes over my career and there is one tool more than any other that I find a genuine hinderance on a day to day basis. This tool is Microsofts large ALM offering – TFS.

Continue reading

Life Through a Lens – Mappers and Wrappers

Mike Edwards (at SUGCON 2015) did an awesome presentation on data modelling (I would highly recommend you check it out if he re-runs it) on the pros and cons of how to model data. Glass Mapper (unlike wrapping frameworks – Synthesis / Fortis) is uses the Data Mapper pattern to represent data. He also wrote a great post here –

This gives distinct advantages in the functionality it can provide in terms of its exposure of native .net types, its ability to be able to read / write between databases, control of serialization, non-reliance on code generation, mocking, testing, caching etc.

It does also have the downside of being heavier on instantiation in comparison to simply wrapping the item and performing casts on demand. It is also further away from the originating record. This also means that unlike wrapping frameworks, the number of mapped properties will actually also impact the overall performance.

Continue reading

Sitecore 8 dialogs not working?

Recently I’ve seen Sitecore fail to load the JavaScript files for Speak and so break using the Sitecore desktop by failing to load dialogs in the content editor and in the control panel. This can happen in a couple of ways and the reasons behind it are pretty subtle. The issue I found for this post was that the SPEAK javascript files were not loading.

The SPEAK system relies on a set of config files in the App_Config/Include folder and client libraries inside the sitecore/shell folder. To ensure that the configuration is loaded correctly and the JavaScript files are returned, you need to check:

  1. ‘/App_Config/Include/.Sitecore.Speak.Important.Config’ – make sure this doesn’t have the hidden attribute set. If you need to, remove the ‘.’ prefix to force a refresh
  2. Double check that all the client assets also don’t have the hidden attribute set.

To test that everything is ok, visit the following URL: <Your_Host>/-/speak/v1/assets/main-1.2.js

You should see the require.js calls setup and loading the libraries necessary for the Sitecore desktop. In another post I’ll cover how you can turn on minification and etags!

Hope this saves you some time!


Did you really mean .Controller() in Sitecore MVC?

Real short post this one, but I have seen this a few times from different developers, so I am now considering that this is a common mistake and can be disastrous for performance.

The mistake is this – developers using code like the following:

@Html.Sitecore().Controller("ControllerName", "MethodName");

This code is fine and dandy IF you want to execute a controller with frills. HOWEVER, the number of times I have seen it used on the Layout to bring in Metadata, Header, Footer or any other statically bound rendering. This WILL BYPASS Sitecore’s output caching mechanisms altogether, so every page of your site (potentially) execute every controller added in this manner.

In the code below, I have simply created a controller rendering in Sitecore (though could be any) and used its ID to display the statically bound rendering using @Html.Sitecore.Rendering().

@Html.Sitecore().Rendering(RenderingConstants.MetaData, new { Cacheable=true, Cache_VaryByData=true })

Note also the EXPLICIT caching, at the time of this post, Sitecore still has an MVC based bug that means the rendering items caching settings are ignored altogether (there is a patch and I hope it will become core)

Continue reading

Allowing unit tests using generic funcs, actions or expressions

The other day, I was required during writing a unit test on a Sitecore pipeline to be able to get the value from a method in a base class in the original Sitecore API. In this case it was Sitecore.Mvc.Pipelines.Response.RenderRendering.GenerateCacheKey, and what I needed to do was get the cachekey from the base and then modify it to add additional string values to the key. In doing so I realised that the standard ‘abstract it away’ didn’t really work in its traditional form, since the abstraction would not be aware of ‘base.’. I could pass in that specific method as an argument, but felt that a better approach might be to create a utility repository that would allow me to execute code with an expected return. This meant using a normal Mock of this approach, I could abstract the code in question and simply return what I expect to be the value, without worrying about it (in this case) actually getting the API involved.

Continue reading

Getting a Sitecore Model From The cshtml (View)

As most of you will no doubt be aware, I am an advocate of using an ORM (you decide – I personally like Glass Mapper For Sitecore) in your Sitecore solutions. A little while back the magnificent John West did a great post on a proof of concept for getting a model from the .cshtml rather than defining it in Sitecore. I thought this was awesome and since then I have been experimenting with it as an idea.

I have kept this example based on vanilla Sitecore, however, would take very minor modification to use with an ORM.

Continue reading

Sitecore WebAPI – Hooking into the route setup

Setting up routes in MVC and WebAPI is pretty straightforward in Sitecore provided that its done in the correct pipeline. When I first started attempting to add routes, I quickly discovered that doing this via the Global ASAX wasn’t reliable. The reason for this is that the routes are setup in the initialise pipeline.

Fortunately Sitecore has this process mapped out in the the config file so all I needed to do is swap out the DefaultRouteMapper that comes out of the box. Lets look at the entry in Sitecore:

<setting name="Sitecore.Services.RouteMapper" value="NAMESPACE.CustomRouteMapper, ASSEMBLY_NAME" />

Continue reading

Sitecore WebAPI – Setting up IOC

I’ve had the opportunity to tinker in the depths of the WebAPI in Sitecore 7.5 and 8 recently. I’ll put up a post about setting up controllers easily shortly but until then I thought I’d share how to setup IOC.

In a normal WebAPI environment, we can create our resolver and attach it to the GlobalConfiguration. However, we must remember that Sitecore uses its own pipelines for MVC and WebAPI and so setting this up in the Global ASAX won’t work.

The way I’ve done it is to change the registered WebAPI initialiser class in the Sitecore.Services.Config file found in App_Config/Include. This lets me hook directly into the entry point for Sitecore related WebAPI and adjust the configuration accordingly.

Continue reading