EPierver has build-in initialization mechanism implemented with Initialization Modules. It’s used to initialize internal code as well as custom functionalities. All classes marked with InitializableModule attribute that implements IInitializableModule interface will be used to setup CMS.
The order of modules execution is controlled by ModuleDependency attribute.
1 2 3 4 5 |
[InitializableModule] [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class CustomInitialization : IInitializableModule { } |
The ModuleDependency constructor takes as a parameter type of another module on which it should depend on. Of course we could set more than one dependent module.
Modules sort order
I wondered which EPiServer module will be executed as the last one? In the documentation we could find that if we need to run custom initialization module after CMS is initialized then we should use EPiServer.Web.InitializationModule dependency.
I tried to prepare a code snippet which will list all InitializationModules in ordered way. To achieve this I used InitializationEngine class.
First, to initialize engine, I called ScanAssemblies method. Then using GetDependencySortedModules I get sorted list.
I was also curious what is the purpose of all those modules. So I read all available information from XML documentation files and combined with current code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
var output = new StringBuilder(); var engine = new InitializationEngine(Enumerable.Empty<IInitializableModule>(), HostType.WebApplication); engine.ScanAssemblies(); var dependencySortedModules = engine.GetDependencySortedModules(); foreach (var module in dependencySortedModules) { var moduleType = module.GetType(); output.Append(moduleType.Name).Append(";").Append(moduleType.Namespace).Append(";"); var dllPath = new Uri(moduleType.Assembly.CodeBase).LocalPath; var docuPath = dllPath.Substring(0, dllPath.LastIndexOf(".")) + ".XML"; if (File.Exists(docuPath)) { var xmlDocument = new XmlDocument(); xmlDocument.Load(docuPath); var path = "T:" + moduleType.FullName; var typeNode = xmlDocument.SelectSingleNode("//member[starts-with(@name, '" + path + "')]/summary"); if (typeNode != null && typeNode.InnerText != null) { output.Append(typeNode.InnerText.Trim(); } } output.AppendLine(); } |
Below is the result of running snippet on on Alloy demo solution. You can see that all custom modules will be executed after EPiServer.Web.InitializationModule module.
Name | Namespace | XML documentation description |
---|---|---|
DynamicDataTransferHandler | EPiServer.Enterprise | Handle transfering Dynamic Data (e.g. PropertySettingsWrapper Setting of PropertyDefinition and Pageobjects on page data are the DDS items) It register self to RegisterTransferHandlers when the system be starts by IInitializableModule (Initialize) |
ProviderBasedLocalizationService | EPiServer.Framework.Localization | Provider based implementation of . Uses s to load localized resources. |
IdentityMappingInitialization | EPiServer.Initialization | |
MirroringMonitoringModule | EPiServer.MirroringService.MirroringMonitoring | |
SearchInitialization | EPiServer.Search | |
ServiceContainerInitialization | EPiServer.ServiceLocation | Initializes the IoC container. To use in an initializable module add from your initializable module to . |
DisplayChannelService | EPiServer.Web | Service that handles instances. |
DisplayOptions | EPiServer.Web | Service that is used to register s |
DisplayResolutionService | EPiServer.Web | |
BundleConfig | EPiServer90Sample.Business.Initialization | |
DataInitialization | EPiServer.Data | |
EventsInitialization | EPiServer.Events | |
FrameworkInitialization | EPiServer.Framework | Initializes framework features |
SecurityEntityProviderInitialization | EPiServer.Framework.Security | |
ClientResourceInitialization | EPiServer.Framework.Web.Resources | Client resource initializer to enable debug mode |
CMSDynamicDataStoreInitialization | EPiServer.Initialization | |
LocalizationInitialization | EPiServer.Initialization | |
MembershipSecurityEntityProviderInitialization | EPiServer.Initialization | |
VisitorGroupsInitialization | EPiServer.Initialization | |
LicensingInitialization | EPiServer.Licensing | |
QueryableNotificationUsersInitialization | EPiServer.Notification | |
ShellInitialization | EPiServer.Shell | Shell Initialization module |
ValidationService | EPiServer.Validation | Default implemetation of IValidationService. |
VisitorGroupTransferDataHandler | EPiServer.Enterprise | Handle transfering of visitorgroup data in the export/import and mirrroring context
Visitor group and visitor group criteria are in the DDS items and it uses the DynamicDataTrafsferHandler |
WebIdentityInitialization | EPiServer.Initialization | |
ExternalDataTracker | EPiServer.MirroringService | This class has tracker on external mirroring data such as VisitorGroup, ContetType and etc. As soon as the entities changed then it sets the entities state as changed in mirroring data |
PackagingInitialization | EPiServer.Packaging | |
VisitorGroupInitialization | EPiServer.Personalization.VisitorGroups | |
InitializationModule | EPiServer.Shell.UI | |
CmsCoreInitialization | EPiServer.Initialization | |
DefaultTaskInformationStorageInitialization | EPiServer.Async | |
BlobRouterInitialization | EPiServer.Initialization | Represents the initialization module for thumbnail image generator. |
CmsDataInitialization | EPiServer.Initialization | |
DynamicContentInitialization | EPiServer.Initialization | |
ParentRestoreInitialization | EPiServer.Initialization | |
VirtualPathProvidersInitialization | EPiServer.Initialization | |
XFormsInitialization | EPiServer.Initialization | |
SchedulerService | EPiServer.Scheduler | |
MvcInitializationModule | EPiServer.Web.Mvc | This class and its members are reserved for internal use and are not intended to be used in your code. |
SaveConfigToDatabaseInitialization | EPiServer.Initialization | |
PlugInInitialization | EPiServer.Initialization | |
ModelSyncInitialization | EPiServer.Initialization | |
UrlRewriteProviderInitialization | EPiServer.Initialization | |
SearchInitialization | EPiServer.Initialization | |
InitializationModule | EPiServer.Web | Initialization of the EPiServer CMS runtime. |
DefaultSiteContentInitialization | EPiServer.Enterprise | Supports automatic setup of default site content (used by templates to bootstrap a site with content) |
LinkAnalyzerInitialization | EPiServer.LinkAnalyzer | |
EPiServerUIInitialization | EPiServer.UI | |
ClassFactoryInitialization | AlloySample.Business.Initialization | |
DisplayRegistryInitialization | AlloySample.Business.Initialization | |
GlobalNewsContentProviderInitialization | AlloySample.Business.Initialization | |
XFormInitialization | AlloySample.Business.Initialization | |
InitializableModule | EPiServer.Cms.Shell | |
SiteMetadataExtenderInitialization | AlloySample.Business |