Migrated article
This article was migrated from an older iteration of our website, and it could deviate in design and functionality.
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.
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.
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:
[InitializableModule]
[ModuleDependency((typeof(InitializationModule)))]
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! :)