WebActivator is not working with Orchard

Topics: General, Troubleshooting
Jun 13, 2013 at 1:47 PM
I have current version of Orchard CMS 1.6.1 and WebActivator 2.0.1.

Default installation of Orchard. WebActivator PreApplicationStartMethod is not fired.

In the same solution I have sample MVC application and the same WebActivator code works fine.

What is wrong with Orchard app. Is it breaks standard ASP.NET pipeline?

Sample code (I've used both Pre and PostApplicationStartMethod):
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(Go2See.Web.App_Start.LocalizationServiceStarter), "PreStart")]
namespace Go2See.Web.App_Start
    public static class LocalizationServiceStarter
        public static void PreStart()
            throw new ApplicationException("x");
Jun 16, 2013 at 3:25 AM
is this a bug?
Jun 16, 2013 at 9:55 AM
Hmm I havent seen anyone using this in Orchard before.

What scenario are you looking at doing? we might be able to help you hook in to the orchard pipeline at the right point.
Jun 17, 2013 at 5:26 PM
IOrchardShellEvents should allow you to accomplish most things you'd use WebActivator for.
Jun 17, 2013 at 10:53 PM
Do not cross-post here and on SO, or at least please provide a link if you already posted the question somewhere else...
Jun 18, 2013 at 3:01 PM
I did not get any feedback on SO so I post here. Sorry.

I need to hook in web app pipeline, not in Orchard pipeline. I know about IOrchardShellEvents.

Also there's some nuget packs uses WebActivator.

So I think that it should be possible to use WebActivator within Orchard installation.
Jun 18, 2013 at 3:04 PM
Edited Jun 18, 2013 at 3:04 PM
i also think that " there's some nuget packs uses WebActivator", which is popular and convinient
Jun 18, 2013 at 3:26 PM
Edited Jun 18, 2013 at 3:43 PM
The reason why there are no answers is because that there is not enough information. What is your setup? Are you trying to do that from a custom module or you're putting code directly into Orchard.Web? And so on.
WebActivator won't work from custom modules - you need to put your code directly inside Orchard.Web to make it work (this is the Orchard's main ASP.NET MVC app).

Anyway - please provide some more detailed description of your use case. The necessity to use WebActivator smells, unless there is a legitimate reason that we cannot see. Orchard has lots of extension points and it's highly likely there is a cleaner solution. Most of the time there will be a way of proceeding without using WebActivator.

@infofromca It's not a bug. I bet there is something wrong with the custom code. Orchard is an ASP.NET MVC application with a framework built on top of it. Anything that's possible in other MVC apps is possible here. The only thing is that the architecture discourages usages of global hooks in favor of using provided extension points (like IOrchardShellEvents etc.) and DI in general. Discourages, not prohibits. There are various reasons behind that with multi-tenancy being the major one (you may have lots of sites with different requirements and settings inside a single Orchard app).
Jun 18, 2013 at 3:38 PM
Edited Jun 18, 2013 at 3:48 PM
@infofromca Being popular/convenient/simple does not necessarily mean that it's the best way to go. There always need to be legitimate architectural reasons behind it. Popularity/simplicity alone is not enough. Otherwise it's the fastest way to end up with a smelly code.

For example - SignalR uses WebActivator by default, but it's perfectly possible to proceed without it in Orchard.
Jun 18, 2013 at 4:18 PM
@pszmyd I've provided full source code. It's separate assemply with only one class LocalizationServiceStarter (full source code of it in the first post above).
It's not in the custom Orchard module.

I do not think that WebActivator smells. It's an easy way for components to hook Application_Start. I'am confused why it is not working in Orchard as well as it is standard MVC app.

For example, there's IIS web application with orchard installed for CMS tasks and some separate code to handle custom tasks. That separate code do not want to have any dependency on Orchard and just want to hook Application_Start.

Also I've tested System.Web.PreApplicationStartMethod - it's not working within Orchard installation also.

For my opinion it will be very useful if Orchard will support standard System.Web.PreApplicationStartMethod. And I think it will not break any Orchard philisophy.