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 topic describes how to create an initialization module to work with the initialization system in the EPiServer platform.
When you create your own 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)
{
}
}
private bool _eventAttached;
public void Initialize(InitializationEngine context)
{
if (!_eventAttached)
{
SomeClass.AnEvent += MyEventHandler;
_eventAttached = true;
}
MethodThatMayThrowException();
}
This Initialize method may generate an error after the event handler is hooked up. The initialization system invokes the Initialize method again on the next request that reaches the web application and if the event hook-up is not protected with a flag, it gets added again.Last updated: Sep 21, 2015