Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can replace the default <em>IModuleInitializer</em> for an instance of a custom class that instead of initializing the modules right after they are loaded, stores them in a modules list. When all modules have been loaded, you initialize them in whatever order you want.</p> <p>How to achieve this:</p> <p>1) In the bootstrapper, override the <em>ConfigureContainer</em> method to replace the default <em>IModuleInitializer</em> for a instance of the <em>MyModuleInitializer</em> class, yet maintaining the default initializer with a name (for example, <em>defaultModuleInitializer</em>):</p> <pre><code> protected override void ConfigureContainer() { base.ConfigureContainer(); var defaultContainer = Container.Resolve&lt;IModuleInitializer>(); Container.RegisterInstance&lt;IModuleInitializer>("defaultModuleInitializer", defaultContainer); Container.RegisterType&lt;IModuleInitializer, MyModuleInitializer>(new ContainerControlledLifetimeManager()); } </code></pre> <p><br/> 2) Create the <em>MyModuleInitializer</em> class that performs the desired storea-all-then-sort-and-initialize procedure:</p> <pre><code> public class MyModuleInitializer : IModuleInitializer { bool initialModuleLoadCompleted = false; IModuleInitializer defaultInitializer = null; List&lt;ModuleInfo> modules = new List&lt;ModuleInfo>(); public MyModuleInitializer(IUnityContainer container) { defaultInitializer = container.Resolve&lt;IModuleInitializer>("defaultModuleInitializer"); } public void Initialize(ModuleInfo moduleInfo) { if(initialModuleLoadCompleted) { //Module loaded on demand after application startup - use the default initializer defaultInitializer.Initialize(moduleInfo); return; } modules.Add(moduleInfo); if(AllModulesLoaded()) { SortModules(); foreach(var module in modules) { defaultInitializer.Initialize(module); } modules = null; initialModuleLoadCompleted = true; } } private bool AllModulesLoaded() { //Here you check whether all the startup modules have been loaded //(perhaps by looking at the module catalog) and return true if so } private void SortModules() { //Here you sort the "modules" list however you want } } </code></pre> <p>Note that after all the startup modules have been loaded, this class reverts to simply invoking the default initializer. Adapt the class appropriately if this is not what you need.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload