This project is read-only.

IOrchardShellEvents order

Topics: Customizing Orchard, Writing modules
Nov 4, 2013 at 5:17 AM

I want to write an event handler class that implements IOrchardShellEvents.Activated, in other words, I need some code to run when the shell is first started.

Orchard comes with a class called AutomaticDataMigrations, which ensures that the latest Database Migrations have been run.

I would like to get the .Activated method on my class to be called after AutomaticDataMigrations.Activated, so that all of the DB tables, etc. are ready before my class is run. However, Orchard seems to always call AutomaticDataMigrations last.

I've tried playing with both the Dependencies field and Priority field in the Modules.txt of my module, but I cannot get my class to run later than AutomaticDataMigrations. Does anyone here possibly have any ideas on how to manipulate the order that these event handlers are run?
Nov 4, 2013 at 5:26 AM
Edited Nov 4, 2013 at 5:27 AM
Here is what I have tried:

When a stock implementation of Orchard using the Core recipe is set up, and my module is enabled, there are just three implementations of IOrchardShellEvents. By default they are called in this order. 1. My custom event handler, 2. AliasHolderUpdater (from Orchard.Alias), 3. AutomaticDataMigrations (from Orchard.Framework).
  • I have tried adding Orchard.Framework to the Dependencies list of my Module.txt. This seemed to do nothing. This does work when I add Orchard.Alias to the list. My class is called after AliasHolderUpdater.Activated. It just does not work for AutomaticDataMigrations, which seems to be part of Orchard.Framework.
  • I have tried adding Priority: 1 to my Module.txt. This does make my class get called after other IOrchardShellEvents implementations, such as AliasHolderUpdater. However, it just does not work for AutomaticDataMigrations.
Really, it seems that it would be much more useful to be able to actually use IOrchardShellEvents.Activated and be sure that database migrations have been run by then, so that the custom Activated event handler can make use of the tables that are set up by the migrations.