EPiServer  /  CMS April 29, 2010

The new initialization process in Page Type Builder 1.2

When I first started developing Page Type Builder I really wanted it to be as easy to use as possible. And as I believe that almost anything that involves human interaction with XML is an anti-pattern to easy usage I didn’t want to force developers to have to configure it in web.config by making it an HTTP module. Still, Page Type Builder needs to be initialized when the application starts. So, I found another way, using a nasty little trick where Page Type Builder’s Initializer class, which initializes the process of updating page types etc, inherited from EPiServer’s PlugInAttribute class.

Overlooking the general nastiness of that solution it came with a problem. If you created a custom property and, before compiling and visiting the site so the property would get registered, added a property to a page type of that type Page Type Builder would sometimes throw an exception as it was asked to create a property definition (it’s actually called PageDefinition but that’s just weird) on a page type of a property type that hadn’t been registered yet.

There has been some discussions back and forth on how to fix this. Unfortunately no proposed solution has been great. Therefore I was very glad to see that EPiServer introduced a new initialization and module system in EPiServer CMS 6. This system, which is very similar to the one that has been around in EPiServer Community for quite some time is really a great improvement and it fits the needs of Page Type Builder well.

Thanks to the new initialization system Page Type Builder’s Initializer class no longer inherits from the PlugInAttribute class, given that you use version 1.2 Beta 2 or newer. It instead implements the IInitializableModule interface and is decorated with a ModuleDependency attribute. Using the ModuleDependency attribute it tells EPiServer Framework’s initialization system that it should be initialized after EPiServer CMS has been initialized, thus ensuring that newly added custom properties are registered before Page Type Builder starts to update page types.

While this change probably won’t matter to the majority of Page Type Builder’s users it is a breaking change for those that have some sort of functionality for creating pages when the application starts if the functionality is dependent on Page Type Builder having been initialized. The solution is very simple and rather elegant: create your own module that implements IInitializableModule and add a ModuleDependency attribute to it with which you specify that the module is dependent on PageTypeBuilder.Initializer. Like this:

using System;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using PageTypeBuilder;

public class StartupPageCreator : IInitializableModule
    public void Initialize(InitializationEngine context)
        //Do your thing, like creating a basic set of pages

    public void Preload(string[] parameters)
        throw new NotImplementedException();

    public void Uninitialize(InitializationEngine context)

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more


comments powered by Disqus

My book

Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!

More about EPiServer CMS