http://www.codedigest.com/posts/1/what-is-owin-a-beginners-guide

http://owin.org/html/spec/owin-1.0.1.html

Introduction

If you look at the current web stacks in open-source, it is fast evolving with wide-range of capabilities getting added day by day.  On the other hand, Microsoft too is constantly working to update its web application stack and released many new framework components. Though Microsoft’s Asp.Net is very mature framework, it had lacked some basic qualities like portability, modularity and scalability which the web stacks in Open Source communities were offering. This had led to the development of OWIN, a specification how an Asp.Net application and hosting servers has to be built to work without any dependency on each other and with minimal runtime packages. By implementing OWIN specification, Asp.Net can become more modular, have better scalability, it can be easily ported to different environments, and thus making it competitive with its open source counterparts. Besides this, it is also aimed to nurture the .net open source community participation for its framework and tooling support.

OWIN

OWIN stands for Open Web Interface for .Net. It is a community-owned specification (or standard) and not a framework of its own. OWIN defines an interface specification to de-couple webserver and application using a simple delegate structure. We will discuss more about this delegate later in this article. Now, let’s take a closer look at classic Asp.Net framework’s design issues in detail and how OWIN tries to mitigate it.

ASP.Net - Webserver Dependencies

Asp.Net framework is strongly dependent on IIS and its capabilities, so it can be hosted only within IIS. This has made the portability of Asp.Net application an impossible task. In particular, Asp.Net applications are basically build upon the assembly called System.Web which in turn heavily depends on IIS for providing many of the web infrastructure features like request/response filtering, logging, etc.

System.Web assembly also includes many default components that are plugged into the Http pipeline regardless of its usage in the application. This means there are some unwanted features that are executed in the pipeline for every request which degrades the performance. This has made the current open source counter-parts like NodeJs, Ruby, etc. perform way better than Asp.Net framework.

To remove these dependencies, to make it more modular and to build a loosely coupled system, the OWIN specification is built. In simple terms, OWIN removes Asp.Net application dependency on System.Web assembly at first place. That being said, OWIN is not designed to replace entire Asp.Net framework or IIS as such, thus when using OWIN model we are still going to develop an Asp.Net web application in the same way we were doing all these days but with some changes in infrastructure services of Asp.Net framework.

The other major drawback of System.Web assembly is it is bundled as part of .Netframework installer package. This has made the delivery of updates and bug-fixes to Asp.Net components a difficult and time consuming task for the Microsoft’s Asp.Net team. So, by removing the dependency with System.Web assembly, Microsoft is now delivering its owin web stack updates faster through its Nuget package manager.

Implementing OWIN

As I said before, OWIN is not an implementation by itself. It just defines a simple delegate structure commonly called as Application Delegate or AppFunc designed for the interaction between webserver and application with less dependency. AppFunc delegate signature below.

Func<IDictionary<string, object>, Task>

可以在Katana的源码中找到

using AppFunc = Func<IDictionary<string, object>, Task>;  https://github.com/aspnet/AspNetKatana/blob/dev/src/Microsoft.Owin.Host.SystemWeb/OwinAppContext.cs#L24

This delegate takes a Dictionary object (IDictionary<string, object>) as a single argument called Environment Dictionary and it returns a Task object. This Dictionary object is mutable, meaning it can be modified further down the process. All applications should implement this delegate to become OWIN complaint.

In an OWIN deployment, the OWIN host will populate the environment dictionary with all necessary information about the request and invoke it. This means it is the entry point to the application, in other words, it is where the applications startup/bootstrap happens. Hence, this is called the Startup class. The application can then modify or populate the response in the dictionary during its execution. There are some mandatory key/values in the environment dictionary which the host will populate before invoking application. Refer the spec under the heading Environment.

Below are the components of Owin-based application that makes this happen. From OWIN spec,

Server — The HTTP server that directly communicates with the client and then uses OWIN semantics to process requests. Servers may require an adapter layer that converts to OWIN semantics.

Web Framework — A self-contained component on top of OWIN exposing its own object model or API that applications may use to facilitate request processing. Web Frameworks may require an adapter layer that converts from OWIN semantics.

Web Application — A specific application, possibly built on top of a Web Framework, which is run using OWIN compatible Servers.

Middleware — Pass through components that form a pipeline between a server and application to inspect, route, or modify request and response messages for a specific purpose.

Host — The process an application and server execute inside of, primarily responsible for application startup. Some Servers are also Hosts.

Building an OWIN complaint application

To be OWIN complaint, our Asp.Net application should implement the application delegate AppFunc. With current set of framework components, we also need the actual OWIN implementation for host, asp.net application and infrastructure service components. So, building Owin complaint application is not just implementing AppFunc delegate alone it also requires other components. Here comes the need of the Project Katana, which is Microsoft’s own implementation of this specification.

The Asp.Net's infrastructure services like Authentication, Authorization, routing services and other request/response filtering has to be done by OWIN middleware pass-through components to prevent its dependency with IIS. These middleware components resembles the Http modules in the traditional Asp.Net pipeline. They are called in the same order they are added in the Startup class similar to HttpModule events subscription in classic Asp.Net application object(Global.asax). To recall, Owin’s AppFunc delegate implementation in our application is commonly called as Startup class. We will understand it better when we build our first application.

Project Katana has evolved so much after its initial release and it is now fully incorporated into the newest version of Asp.Net called Asp.Net Core. Next section will provide us a brief history of OWIN implementation from Project Katana to Asp.Net Core releases.

Project Katana to Asp.Net Core

  1. Project Katana is Microsoft’s first own implementation of OWIN specification and it is delivered as Nuget packages. Developers can include these packages from Nuget and start working.

  2. Microsoft planned for Asp.Net vNext, the next version after Asp.Net 4.6 with full support of OWIN and thus Project Katana was slowly retiring. Note – Any project implementation with Katana libraries will continue to work as expected.

  3. .Net Core 1.0 is another implementation of .NetFramework. .Net Core is a portable, open-source, modular framework and it is re-built from scratch with new implementation of CLR. The Asp.Net vNext, the next version of Asp.Net was renamed as Asp.Net 5.0 and is capable of running on .Net Core framework and latest .Net framework 4.6.2

  4. Asp.Net 5.0 was renamed to Asp.Net Core since this framework was re-written from scratch and Microsoft felt the name was more appropriate. Asp.Net Core is delivered as Nuget packages and it will run on both .Net Core 1.0 and .NetFramework 4.5.1+ frameworks. So, the latest version of Asp.Net is now officially called as Asp.Net Core.

Though OWIN and Project Katana was released years ago, there were lots of updates happened to its implementation all these days. Hope this article helped you understand the current status and start the learning process of building Owin-based application.

Let’s implement a sample Owin-capable application in the next part. Stay tuned!

What is OWIN? A Beginners Guide的更多相关文章

  1. Beginners Guide To Learn Dimension Reduction Techniques

    Beginners Guide To Learn Dimension Reduction Techniques Introduction Brevity is the soul of wit This ...

  2. SystemTap Beginners Guide

    SystemTap 3.0 SystemTap Beginners Guide Introduction to SystemTap Edition 3.0   Red Hat, Inc. Don Do ...

  3. Portrait Photography Beginners Guide

    Please visit photoandtips稻糠亩 for more information. 六级/考研单词: vogue, derive, gorgeous, thereby, strict ...

  4. Beginners Guide To Web Development

    Web Development Front End Development Back End Development

  5. [Selenium.2.Testing.Tools.Beginners.Guide]读书笔记

    Assert, this allows the test to check if the element is on the page, if it is not available then the ...

  6. Understanding and Creating OWIN Middlewares - Part 1

    In my previous article, What is OWIN? A Beginners Guide we learned the basics of OWIN and the benefi ...

  7. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  8. 【深度学习Deep Learning】资料大全

    最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books  by Yoshua Bengio, Ian Goodfellow and Aaron C ...

  9. [Erlang 0105] Erlang Resources 小站 2013年1月~6月资讯合集

    很多事情要做,一件一件来; Erlang Resources 小站 2013年1月~6月资讯合集,方便检索.      小站地址: http://site.douban.com/204209/     ...

随机推荐

  1. 适配器模式(Adpater)

    一.适配器模式介绍 适配器模式:将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的类可以一起工作. 例如: NBA中的球员来自不同国家,而世界标准语言 ...

  2. Browser Cookie Limits

    w https://cait.calarts.edu/hc/en-us/articles/217055138-Error-Maximum-Number-of-Cookie-Values-Reached ...

  3. 设计模式之Prototype模式

    通常我们会使用new 类名()的方法会去生成一个新的实例,但在开发过程中,有时候也会有"在不指定类名的前提下生成实例"的需求,那样,就只能根据现有实例来生成新的实例. 有三种情况, ...

  4. Django REST framework 理解

    ​ Web应用模式 1 .前后端不分离:在前后端不分离的应用模式中,前端页面看到的效果都是由后端控制,由后端渲染页面或重定向,也就是后端需要控制前端的展示,前端与厚度那的耦合度很高. 这种应用模式比较 ...

  5. HTML容易遗忘内容(三)

  6. Linux修改信息

    修改时间 sudo date -s MM/DD/YY //修改日期 sudo date -s hh:mm:ss //修改时间 在修改时间以后,修改硬件CMOS的时间 sudo hwclock --sy ...

  7. TensorFlow学习笔记(五)图像数据处理

    目录: 一.TFRecord输入数据格式 1.1 TFrecord格式介绍 1.2 TFRecord样例程序 二.图像数据处理 2.1TensorFlow图像处理函数 2.2图像预处理完整样例 三.多 ...

  8. matplotlib 的 subplot, axes and axis

    fig = plt.figure('多图', (10, 10), dpi=80) #第一个指定窗口名称,第二个指定图片大小,创建一个figure对象 plt.subplot(222) #2*2的第二个 ...

  9. PKU 3267 The Cow Lexicon(动态规划)

    题目大意:给定一个字符串和一本字典,问至少需要删除多少个字符才能匹配到字典中的单词序列.PS:是单词序列,而不是一个单词 思路:                                     ...

  10. MySQL中锁详解(行锁、表锁、页锁、悲观锁、乐观锁等)

    悲观锁: 顾名思义,很悲观,就是每次拿数据的时候都认为别的线程会修改数据,所以在每次拿的时候都会给数据上锁.上锁之后,当别的线程想要拿数据时,就会阻塞,直到给数据上锁的线程将事务提交或者回滚.传统的关 ...