What I want from Sitecore for Christmas – Thoughts from an opinionated developer

Perhaps contentious perhaps not but as an API I’d like to see a little consistency in the dependencies in Sitecore. Specifically when you look at the various Sitecore modules shipped by them we have Ninject, Unity, SimpleInjector and so on. As hard as it might be to have a specific team move away from their chosen favourite library, for large scale installations we as customers need some consistency in the libraries we use and support in our installations.

I do accept that these modules are supposed to be ‘black box’ but they all end up in the same bin folder and so we as customers have to manage the dependencies. I’m currently working in a Unity shop and so have had to manage the installation of the ECM (which uses Unity 2.x) while we are using 3.5. That’s not so bad but we have these other containers floating around in there too.

So for Christmas I’d like to see a consistent choice in IOC. Or a standardised container interface I can use to inject my own container when using Sitecore modules from other vendors.

Advertisements

Back to Basics: Sitecore validation – part 1

This is the first post in a series about back to basics. All to often I come across Sitecore projects that commit a number of sins. Hopefully this will tie together with the continuing series on working with the Sitecore platform instead of against it. So with that in mind, the first few parts will be about field validation in Sitecore.

Field validation is often overlooked. I think in part because the template editor has a quick and dirty interface for setting all the common properties such as name, source, shared etc. But to setup the validation, help text and the like you have to go into the field itself.

However, the content editors experience can be greatly enhanced with good validation with clear, concise error messages. It also means that as developers, we can enforce a little safety in our environment and increase our chances that our code will get data in the right ‘shape’.

A short history lesson

Before Sitecore 5, validation was done with regular expressions and a generic error message. This would fire and the user would see a popup with that message. After a while this would get pretty annoying as the editor couldn’t really see which fields were invalid and, in some cases, the warning wasn’t a critical error. Inevitably, unless all of the fields were required and the error messages could be made verbose enough, validation was turned off.

Even now Sitecore 7.x supports this functionality but using it is an incredibly bad idea.

Sitecore validation done right

Validation done right means you need to use the validators built into Sitecore (or add your own) using the various multi-lists directly on the field item for your template. If you do so, you have the advantage that as the editor builds their content, they get visual cues as to which field is incorrect. This appears as a red bar next to the field and colour spots to the top right (in the content editor). You also have the advantage that you can set the levels of these errors and class some as critical meaning the user can’t progress without fixing and you can make others ‘a bad idea’.

More importantly, these are all written in .NET code. What this means is that when you write your own, you’ll be able to unit test them under various conditions and more easily have them as part of your continuous integration builds.

In summary

This post was particularly short as an introduction to validators but they are more of a ‘show me the code’ topic. Its also pretty near to Christmas and I have small people to entertain! 🙂

In my next post on this topic, I’ll look at writing a very simple validator, registering it with Sitecore and setting its error level. More importantly, we’ll look at making it have different options per language and so handle some interesting scenarios. We’ll also have a unit test setup for it and I’ll put it on Github for reference.

 

Making backups and importing data – Mongo and xDB part three

There are a few ways you can make a backup with Mongo. The most simple is to take a copy of the database files and put them somewhere safe. This is made easier if you’ve put each database into its own directory. However, this is a pretty naive method as you will have to stop the server and restart it. You also will be taking a full backup. That said, this method does have its uses in a scenario where you are messing around with a secondary but that’s beyond the scope of this short post.

Its possible to extend this a little by using mongodump against the file system. The tool will lock the files so the database cannot be in use at the time but it at least provides a binary export of the data.

For a developer scenario, its more likely that we’ll be using mongodump, mongorestore, mongoimport and mongoexport against our running database. We may need some data from a co-worker or from the live system or we may be the provider of some data to another member of our team.

Continue reading

Securing and navigating around xDB – Mongo and xDB part two

Peeking around

There are a number of options for navigating your way around Mongo. Depending on what you’re most comfortable with, you may prefer using command line tools and batch files or you may prefer GUI tools like RoboMongo, MongoChef or MongoVue. That said, for the more complex operations you’ll have to be comfortable with the command line tools unless you’re hosting with a third party.

The Mongo eco-system is based on a Javascript ‘shell’. This means that all functions, loops and the like follow the normal Javascript syntax rules. It also means that reading any custom functions and profile scripts should be easy for anyone who is familiar with Javascript for web development. Before we continue and look at some simple operations, its useful to repeat some Mongo definitions. Naturally these are all available on the Mongo documentation website so I’ll be brief:

  • Database – the same concept as in a relational product like Sql Server.
  • Collection – similar to a table but doesn’t have a schema
  • Document – a record in a collection.
  • Index – the same concept as in a relational product

When we want to insert data into Mongo, we create a new document and add it to a collection. Mongo also allows us to embed one document inside another which can be useful but does require some care when constructing queries and designing indexes. Once we have some documents, we can pull them out using queries (as you’d expect). These queries can have a bit of a ‘linq’ feel to them due to the use of the Javascript shell. Here’s an example:

use myusertable
db.users.find({"Country": "New Zealand"}).sort( { "Surname": 1, "Firstname": 1 } )

Continue reading

Don’t Fight The Framework – Strategies to optimise Sitecore MVC Performance

After now a couple of weeks of performance optimisations on Sitecore 7.2, I thought I would detail a little bit about ways you can optimise the performance of your MVC based Sitecore solutions.

Before I go any further with this post, I would like to make it clear that I have actively engaged with Sitecore UK and Sitecore support, sent them all of my findings and made performance improvement suggestions based upon my findings. These will hopefully benefit us all in future updates and if you come to the load testing / performance optimisation phase of your project, I would highly recommend you do the same.

Below you will find a summary of the results of my findings during performance and load analysis on Sitecore. For one of my latest builds for a client, we have pretty much followed as close to best practice as we possibly could (including a site review by Sitecore themselves and actions out of it as such), we underwent load testing on the first generation of the clients new site. The site did perform to the acceptance criteria of approximate 12,000 requests a minute that is required for the site at peak time – but not by much. It also VASTLY outperformed it’s predecessor which was a Sitecore site built by a reputable UK Sitecore partner. Since the results were close to the limit though (and to allow for overhead to allow future growth) I found myself having to analyse the performance of various elements of our solution and subsequently of Sitecore itself in order to gain the maximum out of our build.

Continue reading

Getting started – Mongo and xDB part one

With the release of Sitecore 7.5 we saw the introduction of NoSQL to the Sitecore ecosystem. Sitecores platform of choice is MongoDB, an open source document database that runs as a separate server. MongoDB stores all of its data as memory mapped files in a format very similar to JSON (called BSON).

By default, Sitecore Analytics now requires both SQL Server and MongoDB to operate. MongoDB provides much of the data capture and storage and SQL Server the aggregation of that data. Additionally, the ECM and WFFM for Sitecore 7.5 now also use the xDB platform and so also use MongoDB by default.

Its worth knowing this as any implementation of Sitecore 7.5 (or an upgrade to it) will need the infrastructure to support a Mongo installation. Reading through the xDB documentation, it isn’t immediately clear what is required of an xDB infrastructure and it does require quite a bit of background reading. This first post, of a series, is intended to give you a background in some of the items you’ll need to be aware of and also how this relates to Sitecore.

Continue reading

Agnostic IoC De-branded

A quick morning post for any users of Agnostic IoC and anyone thinking about it.

If you have used it, you will have noticed that the binaries and namespaces referred to ‘Cardinal.IoC’. This was a decision made a long time ago, as the original idea for this project was to be part of a bigger ecosystem.

I took the decision well over a month ago that Agnostic IoC was to be de-branded and (due to large work commitments, house move and just life) I have finally managed to achieve this.

For existing users – this will mean that instead of ‘Cardinal.IoC’, it will now be ‘Agnostic.IoC’ at the start of the namespaces.

I think this is a great little utility library and hopefully it will continue to grow with you guys’ support.

Please do contact me with feedback, questions or general abuse 😀

Nat.

Glass Mapper – Agnostic IoC Source

Just a very quick post

This evening I released the source for Glass Mapper running on Agnostic IoC in a more useable format.

You can find it here

https://github.com/cardinal252/Glass.Mapper.AgnosticIoC

This is a great opportunity to get to grips with how Agnostic IoC can be used (especially with Sitecore) to give your modules the flexibility you desire them to have.

Please do feedback on your experience.

Nat