To get access to a page using Episerver, you can use the IContentLoader API.

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 references all over their codebase, 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 (content) 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. Below lists, some other useful API calls for quick reference How to get all child pages

Return all content items up to, and including, the root page

Compare if two content items are the same

Do you know any other useful Epi API calls ? Leave your most used snippets in the comment section below.

How To Access A Page Using Episerver 6

In very early versions of Episerver you could access a page using the DataFactory, like so: