OWIN结构层
OWIN 中的 Host 和 Server
Host
Host(主机):运行应用程序的进程,可以是从 IIS 或独立可执行文件到自己的自定义程序的任何内容。主机负责启动、加载其他 OWIN 组件和正常关闭,主机一般可以看作是服务器的操作系统提供的进程。
从概念上理解,Host 其实就是一个进程,用于管理 OWIN 组件的一些操作,对于现在的 ASP.NET 5 应用程序部署来说,Host 一般有两个选择:Self-Host 和 IIS。
Server
Server: While the host is responsible for starting and maintaining process within which the application runs, the responsibility of the server is to open a network socket, listen for requests, and send them through the pipeline of OWIN components specified by the user (as you may have already noticed, this pipeline is specified in the application developer’s Startup class).
Host 是管理 OWIN 组件的一个进程,而 Server 则是监听请求,并分发请求给对应的 Middleware 中间件进行处理(Startup 中指定),也就是说 Server 只负责监听与分发,不负责处理。
Middleware
称之为中间件、组件,位于Server与Application之间,用来处理发送到Pipeline中的请求,这类组件可以是简单的Logger或者是复杂的Web Framework比如Web API、SignalR,只要Sever连接成功,Middleware中间件可以是任何实现应用程序委托的组件。
Application
这是具体的应用程序代码,可能在Web Framework之上。对于Web API、SignalR这类Web Framework中间件而言,我们仅仅是改变了他们的托管方式,而不是取代ASP.NET WEB API、SignalR原先的应用程序开发。所以该怎么开发就怎么开发,只不过我们将他们注册到OWIN Pipeline中去处理HTTP请求,成为OWIN管道的一部分,所以此处的Application即正在意义上的处理程序代码。