本文介绍了WebActivatorEx VS OwinStartup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在例如一个的WebAPI应用,是

In a WebAPI application for example, what is the difference between

[assembly: OwinStartup(typeof(MyClass), "MyMethod")]

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(MyClass), "MyMethod")]

推荐答案

他们都是在意义上的高水平,他们让你开展你的web应用程序的初始化相似,但它们在一些重要方面不同如下:

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:


  1. WebActivatorEx有针对性的方法。preApplicationStartMethodAttribute 应用程序已经启动之前将执行。这允许你做这样的事情注入一个HttpModule等。

  2. 通过 OwinStartupAttribute 定位
  3. 方法应用已初始化后,将被执行。这是因为这种启动是由 OwinHttpModule 引用这本身就是注射用的System.Web。preApplicationStartMethodAttribute

  4. Owin启动可以通过配置使用的web.config中owin内appsetting被禁用:AutomaticAppStartup

  5. 还有的System.Web。preApplicationStartMethodAttribute 其中作为.NET 4.5可以在装配中多次使用。

  1. Methods targeted by WebActivatorEx.PreApplicationStartMethodAttribute will execute before the Application has started up. This allows you to do things like injecting an HttpModule etc.
  2. Methods targeted by 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.
  3. Owin startup can be disabled via configuration by using an appsetting within web.config of owin:AutomaticAppStartup
  4. There is also 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.


  1. 的System.Web。preApplicationStartMethodAttribute

  2. WebActivatorEx。preApplicationStartMethodAttribute

  3. Global.asax中(的Application_Start 法)

  4. OwinStartupAttribute

  1. System.Web.PreApplicationStartMethodAttribute
  2. WebActivatorEx.PreApplicationStartMethodAttribute
  3. Global.asax (Application_Start method)
  4. OwinStartupAttribute

这篇关于WebActivatorEx VS OwinStartup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:41