Module lifecycle
Modules go through various stages in terms of setting themselves up and shutting down as follows:
- An instance of the module is constructed, and it runs its constructor, which should only set values in the module itself and not rely on any Lynicon systems being in existence.
- In LyniconConfig.RegisterModules() the instance of the module type is registered with LyniconModuleManager:
LyniconModuleManager.Instance.RegisterModule(module); - At the end of LyniconConfig.RegisterModules(), LyniconModuleManager.Instance.ValidateModules() is called which ensures that all module dependencies are in place and correct
- AreaRegistration.RegisterAllAreas() is called in global.asax.cs which in turn runs the AreaRegistration-inheriting class in each Lynicon assembly. The RegisterArea() override in this class will call LyniconModuleManager.Instance.EnsureRoutes() with the AreaRegistrationContext and the namespace of the assembly. This will find all modules with that namespace and run their RegisterRoutes() method to register any routes they need to set up. Notice these routes will be in the Area associated with the Lynicon assembly.
- At the end of LyniconConfig.Initialise(), LyniconModuleManager.Instance.Initialise() is called which runs initialisation code on all the modules in the correct sequence as specified by the dependency constraints of the modules. This performs the bulk of the module initialisation and can rely on the Data system being set up. It sets up processors for any global events and sets up CMS UI changes.
- Once the site is initialised, generally module code can be called by client code, or as a result of actions which raise global events which the module processes, or via UI actions on custom UI.
- When the site shuts down, the event in global.asax.cs calls LyniconConfig.Shutdown() which in turn calls LyniconModuleManager.Instance.Shutdown() which then calls the Shutdown() method on all the modules.