[InitializableModule]
[ModuleDependency(typeof(MyOtherStartupModule))]
public class MyStartupModule : IInitializableModule
{
private bool _eventsAttached = false;
#region IInitializableModule Members
public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
// Attach event handlers unless they've already been attached
// The initialize method may be executed repeatedly if an exception
// is thrown, but we don't want additional event handlers to attach
// if the exception is thrown later in the call stack
if(!_eventsAttached)
{
// Attach event handler to when a page has been created
DataFactory.Instance.CreatedPage+=CreatedPageHandler;
_eventsAttached = true;
}
}
public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
// Detach event handlers
DataFactory.Instance.CreatedPage -= CreatedPageHandler;
}
public void Preload(string[] parameters)
{
throw new NotImplementedException("No preload required");
}
#endregion
void CreatedPageHandler(object sender, PageEventArgs e)
{
// Do something with the new page
DoSomething(e.Page);
}
}