In a WebAPI application for example, what is the difference between
[assembly: OwinStartup(typeof(MyClass), "MyMethod")]
and
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(MyClass), "MyMethod")]
?
The OwinStartup attribute specifies the production startup class is run. Create another OWIN Startup class and name it TestStartup . Replace the generated code with the following: C# Copy.
I found the answer here:
In new SignalR API not using WebActivatorEx anymore. OwinStartup preferred instead of WebActivator.
They both are similar at a high level in the sense that they allow you to carry out initialization of your web application, but they are different in some important ways as below:
WebActivatorEx.PreApplicationStartMethodAttribute will execute before the Application has started up. This allows you to do things like injecting an HttpModule etc.OwinStartupAttribute will execute after Application has initialized. This is because this kind of startup is invoked by OwinHttpModule which in itself is injected in using System.Web.PreApplicationStartMethodAttribute.owin:AutomaticAppStartup
System.Web.PreApplicationStartMethodAttribute which as of .NET 4.5 can be used multiple times within an assembly.So to summarise, this is the order of execution of methods depending on the attributes used.
System.Web.PreApplicationStartMethodAttributeWebActivatorEx.PreApplicationStartMethodAttributeApplication_Start method)OwinStartupAttributeIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With