ClassFactory not initialized exception in InitializableModule
The new initialization system in EPiServer 6 can be used to execute logic in a specific order on startup. This post explains how to ensure your startup modules are executed after the DataFactory has been initialized properly.
Initialization mechanism in EPiServer 6
EPiServer 6 uses a new way of executing logic on startup. Have a look at How to attach event handlers on startup using InitializableModule for details on how this works.
ClassFactory exception when accessing DataFactory methods
If you try to access DataFactory methods such as GetPage in the Initialize() method of an InitializableModule you may run into a ClassFactory not initialized exception. To ensure the DataFactory is initialized before calling its methods you need to explicitly add a dependency to ensure your module isn’t being intialized too early.
Adding a dependency to ensure DataFactory is initialized
To make sure the DataFactory is ready before accessing it when initializing your module you can add the following ModuleDependency attribute to your InitializableModule class:
public class PageTags : IInitializableModule
public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
// It's now safe to access DataFactory methods here
Thanks to Frederik Vig for helping in figuring this out! :)