<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1639164799743833&amp;ev=PageView&amp;noscript=1">
Diagram Views

EPiServer: Not Your Typical Content Management System

Brad McDavid
#Episerver-Ektron Merger, #Episerver, #Code
Published on March 24, 2015
warren-wong-323107-unsplash-1

Learn how developers can use EPiServer's initialization system to extend the capabilities of the CMS.

Following the recent merger between EPiServer and Ektron, developers who are familiar with the latter platform are learning more and more about the capabilities of the former. As we continue to examine how developers can familiarize themselves with EPiServer, we wanted to highlight one particular capability of the platform: Initialization.

EPiServer follows the definition of a typical content management system (CMS) in the respect that content can be created, edited, organized, and deleted in a central user interface, but it provides a great deal of capability beyond that basic level. At the core of what makes EPiServer a great CMS and really more of a platform is its robust initialization system that runs every time the website starts. This initialization gives developers hooks into key system events that can extend and even customize many areas of the CMS.

How Initialization Works

There are 3 main programming interfaces where developers can begin to extend the EPiServer CMS:

  • EPiServer.Framework.IInitializableModule – the base level interface exposes two events: Initialize and Uninitialize. In versions prior to version 8 it also contained Preload, but this has since been dropped.
  • EPiServer.ServiceLocation.IConfigurableModule – inherits Initialize and Uninitialize, but adds ConfigureContainer, which allows for customizing the EPiServer Inversion of Control (IOC)/ Dependency Injection (DI) services using the StructureMap container.
  • EPiServer.Framework.IInitializableHttpModule - inherits Initialize and Uninitialize, but adds InitializeHttpEvents, which is the equivalent of the Init function of the ASP.Net IHttpModule.

Note: Creating a class that implements one of these three interfaces is not all that is needed before the module is loaded during initialization. The implementing class must also use a class attribute of InitializableModule or ModuleDependency. The latter provides a sorting mechanism so that modules that need to override another module’s settings can be executed after the initial module has been run.

If you would like to see this code in action, we’ve created some examples that you can download on GitHub.

When the web site starts, a scan of all compiled code (DLL files) in the site’s bin folder occurs, and every class that implements one of the above interfaces decorated with an attribute is loaded and executed. If for any reason a module starts behaving badly, EPiServer provides a way to remove it from the scan. In the episerver.Framework web.config section, simply change:

<scanAssembly forceBinFolderScan="true">

to

<scanAssembly forceBinFolderScan="true">
<add assembly="*" />
<remove assembly="FullName.Of.Misbehaving.Assembly" />
</scanAssembly>

This directs the assembly scan to skip over looking for any IInitializableModule classes in the assembly matching the value of the assembly name given in the remove line.

Why Initialization Is Important

The code-driven hook in EPiServer’s initialization systems are great, since they typically require zero editing of configuration files, which often get overlooked when installing or deploying code changes. This is especially true for a typical IHttpModule, which by default requires a line for each module in the web.config file for the web site.

Below are some typical scenarios:

  • Customizing default behaviors – The Alloy MVC starter site provides a great example of customizing the default functionality for displaying items in a content area to allow for CSS classes with the Twitter Bootstrap framework. This allows for content areas to create responsive-friendly, dynamic web pages.
  • Reducing risks – The ability to modify extraneous information in HTTP response headers, such as removing web server version, ASP.Net version, MVC version, or inserting security related HTTP headers.
  • Simplified global.asax – Many common tasks typically done in the global.asax file can be split into smaller IInitializableModule classes, such as MVC route registration and error handling.

Since modules are discovered during the website startup scan, they are a great tool to create reusable code, which is especially useful if you manage multiple sites or build sites starting with a common code core.

The initialization system is a robust mechanism which allows the EPiServer CMS to transform into more of a platform to build on top of, rather than a system to manage your content. This is just one example of the powerful tools that EPiServer provides to developers. As we learn more about how the platform will continue to evolve following its combination with Ektron, we’re excited to discover and share the ways developers can utilize it to build websites that utilize the most current technology and provide the best experience for their users. If you have any questions about EPiServer development, please contact us to speak to a Solutions Engineer, or feel free to leave a comment below.