Application_Start extension point?

Topics: Customizing Orchard
Nov 4, 2011 at 7:23 PM

Let us say that I have some code I would like to execute at application startup.

Is there an Orchard extension point I should use for doing this, in order to avoid modifying Orchard.Web\Global.asax.cs?

Coordinator
Nov 4, 2011 at 7:25 PM

No, there isn't one. What is the code you need to execute at application startup?

Nov 4, 2011 at 7:49 PM
Edited Nov 4, 2011 at 7:49 PM

I created a module that I use to generate view models.  The module needs to call out to a WCF service to retrieve data.  I'm using WCF Contrib to assist in consuming the WCF service (we develop the service, and using WCF Contrib makes this more convenient, among other reasons).  Using this component requires a one-time method call which is intended to run once, at application startup (ClientChannel<T>.LoadRuntime()).  So I could modify global.asax.cs, but would rather avoid modifying Orchard's code if possible.

Coordinator
Nov 4, 2011 at 7:51 PM

Well, you won't be able to use WCF Contrib then, sorry, unless you can call this method lazily later, the first time the API is used.

Nov 4, 2011 at 8:08 PM
Edited Nov 4, 2011 at 10:06 PM

One option we've considered is using WebActivator, which might let us keep our WCF Contrib startup code in the module.  We tried this, but it did not work.

Nov 4, 2011 at 9:14 PM
Edited Nov 4, 2011 at 9:14 PM

You can run code very early in the application lifecycle by implementing IOrchardShellEvents. You can write an Activating() method that will run when each shell is initialised (before the first request comes in) - Routable uses this to build its url table. This would probably suit your needs.

Coordinator
Nov 4, 2011 at 9:16 PM

True. Good catch.

Nov 4, 2011 at 10:13 PM

Sounds like a good solution. Thanks.

Apr 23, 2013 at 2:39 PM
I would like to know if in Orchard 1.6 there is a way to extend Application_Start in order to avoid modifying Orchard.Web\Global.asax.cs?
Coordinator
Apr 24, 2013 at 2:04 AM
Please read the messages above.
Apr 24, 2013 at 6:32 AM
Sorry, I didn't read that part, thank you.