Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
This document describes how to create an initialization module to work with the initialization system in the EPiServer platform.
When creating your own initialization module you need to 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)
{
}
public void Preload(string[] parameters)
{
}
}
private bool _eventAttached;
public void Initialize(InitializationEngine context)
{
if (!_eventAttached)
{
SomeClass.AnEvent += MyEventHandler;
_eventAttached = true;
}
MethodThatMayThrowException();
}
This Initialize method may throw an exception after the event handler has been hooked up. The initialization system will re-invoke the Initialize method on the next request that reaches the web application and if the event hook-up is not protected with a flag it would get added again.Last updated: Feb 23, 2015