This project is read-only.

Filter execution order / Equivalent of Application_BeginRequest

Topics: Core, Customizing Orchard, Writing modules
Aug 7, 2012 at 11:03 AM
Edited Aug 7, 2012 at 11:12 AM

I want to run some code as close to the beginning of a request as Orchard will let me, ideally without changing the core Orchard code. It needs to run before all filters.

The OnActionExecuting event of an IActionFilter is as close as I've got so far, but it needs to run before all other filters and I don't think I can change the order they're executed can I?

Really I need the equivalent of the Application_BeginRequest event for the current Orchard Shell. Could someone point me in the right direction?

Aug 7, 2012 at 3:02 PM

Try doing your stuff in the constructor of your IActionFilter class?

Or isn't that constructed once per request?

Aug 8, 2012 at 4:32 PM
Edited Aug 8, 2012 at 4:32 PM

Perhaps implementing IAuthorizationFilter may work for you, as this type of filter runs before all other type of filters.

Aug 9, 2012 at 5:42 AM

@AimOrchard: in general, doing stuff in the constructor is a really bad idea.

Aug 9, 2012 at 6:51 AM

In general yes, but if you reaaally want to do something before anything else it might have a valid reason to do so ;)

I for example use the constructor of a IResourceManifestProvider implementation to resolve a singleton service (as in it is one of the constructor parameters) that will launch background threads.

But in general I agree that doing stuff in a constructor is a bad idea :P

Aug 10, 2012 at 4:02 AM

I'm not following. Dependency injection (of singletons or otherwise) in constructors is standard practice. Is that what you're referring to?