2

I've SignalR 2.x and ASP.NET with ServiceStack framework. It makes to entry points, one per each pipeline:

  1. Startup.Configuration(IAppBuilder app) -- for SignalR startup configuration and
  2. Global.Application_Start() in Global.asax.cs -- for initializing the standard ASP.NET pipeline.

I'd like to pass some object that has been created in Application_Start() into Configuration() (e.g. IOC instance). For this I'd like to be sure that Configuration() will be called after Application_Start().

I found this stackoverflow question. What bothering me is the slightly later definition. Does it mean the execution is overlapped? Is it promised that the code in Configuration() will be called after Application_Start() for sure?

Does anybody know how it is exactly working and what is this delay? Has anyone had an experience with coding these methods?

Thank you

Community
  • 1
  • 1
Leo Y
  • 659
  • 7
  • 22

1 Answers1

1

Iv decided to confirm my previous (and incorrect) statement by experiment and indeed Application_Start() method is called before any Owin startup class which means before SignalR Configuration (assuming recommended SignalR configuration using Owin startup of course).

It is true that Owin (Microsoft.Owin.Host.SystemWeb to be precise - which is Owin host adapter for IIS) uses System.Web.PreApplicationStartMethodAttribute to hook into ASP.NET pipeline but only to register its own OwinHttpModule (and yes this registration happens before Application_Start()). But Owin startup classes are discovered and run during OwinHttpModule.Init() which happens after Application_Start(). Slightly later means exactly that - both methods are called during execution of HttpApplication.RegisterEventSubscriptionsWithIIS private method. No overlaping for sure...

Sidenote: Imho there is no reason to have startup\configuration in two different places in application and because OWIN is the next big thing in ASP.NET world (see vNext or SignalR) and offers more benefits than Application_Start() (such as switching startup configuration in web.config), I'm definitely planning to migrate all Application_Start() code to OWIN startup. -> No reason to worry about what's happening 1st ;)

And this is also my suggestion to you!

Michal Levý
  • 33,064
  • 4
  • 68
  • 86
  • Thank you for the links. Though, I'm not sure what is incorrect in the answer in the link. The blog post that you provided states that for ASP.NET 4 and later the way to execute code before Application_Start() is to use the `PreApplicationStartMethodAttribute`. I understand that. However, it doesn't answer my question regarding SignalR and OWIN. Since it doesn't explain how OWIN initialization cycle works, how SignalR integrates into it and how the OWIN initialization is correlated (if any) with ASP.NET initialization cycle. – Leo Y May 31 '15 at 15:16
  • Thank you. Can you provide the source for this statement: "Owin uses System.Web.PreApplicationStartMethodAttribute"? – Leo Y Jun 02 '15 at 16:40