If you are asking yourself why the second snippet is better, I’ll explain. In the original version 6 API a singleton pattern was used, called the DataFactory, to access data . This meant developers had to implement a lot of concrete reference all over their code base, which makes unit testing a massive pain in the bum. As I’m sure most developers know, working towards SOLID principles is a desirable design concept as it allows you to swap out or moc key bits of functionality that can’t be unit tested. Working with abstractions rather than concrete implementations helps us, as developers, to create more flexible and testable systems. With the second method we call the abstraction (the interface) and not the concrete implementation. This, in theory, would allow you to inject the interface into your repository and create a testable class.

Secondly, the CMS no longer only works with just pages but instead the more general content concept (IContent) has been introduced that allows developers access to a whole range of content. This means that in EPi7 you now have access to objects that may not be page objects anymore. Using the second approach provides more flexibility to cater for different types of content in the future.

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Trackbacks & Pingbacks

[…] In EpiServer 8 we have two new EpiServer APIs for fetching and modifying content. These are the IContentLoader and the IContentRepository. In todays guide I’m going to covoer how to do some basic API calls and explain the difference between the two. This article is a follow on from How to get a page in EPiServer 7? […]

NEED AN EPISERVER DEVELOPER?

Connect

Hi, I'm Jon, I write articles about creating and optimizing websites as well as making money from your online business. I am technical architect and technology fanatic by profession. You can find out more about me by signing up to my newsletter.