OWIN启动的剖析 [英] Anatomy of an OWIN Startup
问题描述
OWIN Startup类上的所有钩子是什么?这些方面的信息很少.
What are all the hooks on the OWIN Startup class? Information on these is scarce.
例如,每个Startup类的一个必需钩子是它应该具有Configuration
方法.可以从 Microsoft文档.
For example, one required hook on every Startup class is that it should have a Configuration
method. This information can be gathered from the Microsoft documentation.
class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
...
}
}
在框架中具有IOwinStartup
接口或OwinStartup
基类的 not 背后的原理是什么?
What is the rationale behind not having an IOwinStartup
interface or OwinStartup
base class in the framework?
interface IOwinStartup
{
void Configuration(IAppBuilder appBuilder);
}
如何对基于OWIN的应用程序执行清理? OWIN是否在启动类上检测到Dispose
方法,类似于它检测到Configuration
方法的方法?
How do I perform cleanup for my OWIN-based application? Does OWIN detect a Dispose
method on the Startup class, similar to how it detects a Configuration
method?
After a lot of searching I found this related question: In self-hosted OWIN Web API, how to run code at shutdown? It's not clear how the peopled who answered that question arrived at the necessary information. Am I missing critical documentation or are these details of the OWIN Startup class as elusive as they seem?
推荐答案
与其说是钩子",倒不如说是惯例.这里有一篇很好的文章:
It's not so much a "hook" as it is a convention. There is a good article on this here:
http://www.asp. net/aspnet/overview/owin-and-katana/owin-startup-class-detection
关于为什么没有接口的原因,很可能是因为不需要将其锁定到该级别.这很大程度上是基于反射的,您可以通过各种配置参数指定用于启动的类和方法.
As for why there is no interface, most likely it's because there was no need to lock it down to that level. This is largely reflection based, and you can specify the class and method to use for startup by various configuration parameters.
对于要链接到的示例中的WebAPI,可以在WebApp.Start方法中执行此操作,并使用要使用的方法名称指定StartOptions,但约定为Configuration.
In the case of WebAPI in the example you link to, you can do so in the WebApp.Start method, and specify StartOptions with the name of the method to use, but the convention is Configuration.
清理可以通过获取取消令牌来完成.该信息在文档中,该文档与您显示的示例链接在一起.我不确定我是否能理解您得出的结论,即文档显然不存在时,文档会丢失.
Cleanup can be accomplished by getting the cancelation token. This information is in the documentation, which is linked from the examples you show. I'm not sure I understand how you arrive at the conclusion that the documentation is missing when it's clearly not.
当然,这里缺少详细的说明和示例...但是有很多关于此内容的博客文章...
Certainly, it's missing elaboration and examples... but there are a lot of blog entries about this stuff...
您可能还需要阅读OWIN规范:
You may also want to read the OWIN specification:
http://owin.org/spec/spec/owin-1.0. 0.html
这篇关于OWIN启动的剖析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!