Create an initialization module
Create an initialization module to work with the initialization system in CMS 12.
When you create your initialization module, add a reference to EPiServer.Framework.dll. The following Initialization code example shows how a property is set up with a default implementation in Initialize, and then the process is undone in Uninitialize:
[InitializableModule]
public class SampleInitialization: IInitializableModule {
public void Initialize(InitializationEngine context) {}
public void Uninitialize(InitializationEngine context) {}
}- The initialization engine ensures that your code executes in a single-threaded manner.
You do not need to lock regions when you deal with a shared state. This guarantee is only made forInitializeandUninitializewhen you execute through the initialization system. You may have to deal with multi-threading issues if you have custom code that makes calls directly into your initialization module. - Remember that the initialization system tracks the initialization state of your module.
- Do an implementation of Uninitialize.
Anything you do withInitializeyou should undo withUninitializein the reverse order of Initialize. This is especially important if you write integration tests that reset applications between test runs. - If you are using the Optimizely Content Management System (CMS) API, make sure you are adding a module dependency to CMS using
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))].
Updated 7 days ago