This project is read-only.

Application_Start extension point?

Topics: Customizing Orchard
Nov 4, 2011 at 8: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?

Nov 4, 2011 at 8:25 PM

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

Nov 4, 2011 at 8:49 PM
Edited Nov 4, 2011 at 8: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.

Nov 4, 2011 at 8: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 9:08 PM
Edited Nov 4, 2011 at 11: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 10:14 PM
Edited Nov 4, 2011 at 10: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.

Nov 4, 2011 at 10:16 PM

True. Good catch.

Nov 4, 2011 at 11:13 PM

Sounds like a good solution. Thanks.

Apr 23, 2013 at 3: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?
Apr 24, 2013 at 3:04 AM
Please read the messages above.
Apr 24, 2013 at 7:32 AM
Sorry, I didn't read that part, thank you.