Hello, Infragistics Community! We are CODEFUSION, a small software development company from Opole, Poland, and this is the first of our posts for our friends at Infragistics.
For our summer internship program we are developing a custom monitoring service for web applications. As usual, in such cases it is an opportunity for our students to explore new directions that technology is taking. This time it was decided to go with the newest ASP.NET MVC 6 and possibly with OWIN/Katana. But do these things work together? Let’s see what our researchers found out:
OWIN
OWIN (The Open Web Interface for .NET) is an open source specification that defines an abstract layer (middleware) between a server and web application. OWIN's main goal is to simplify the creation of scalable components for server-based .NET web apps, by decoupling the web server and the application.
In effect, using the abstract layer implies two main elements. The first one is a dictionary environment which is responsible for keeping all HTTP reply and request states (header and bodies). This initialization looks like this:
IDictionary;
Here, the server fills up a dictionary and passes it to the application, which decouples the application from the server (application works directly with the dictionary and does not need to communicate with the server).
The second important thing in OWIN specification is the generic Func delegate. This delegate makes it possible for the server to be the main interface between all of the application components. This definition looks like this:
Func<IDictionary, Task>;
This Func delegate takes a dictionary environment as a parameter and returns a Task. This solution gives us:
- Lesser dependency between components, thus developers can have greater access to OWIN.
- Because the delegate is an atomic unit and the dictionary is sent as a parameter to this delegate, OWIN components can be easily connected creating HTTP complex message chains.
So to sum up, OWIN is not an implementation but a specification of how web frameworks and web servers interact with each other.
Katana
Katana is OWIN's open source implementation created by Microsoft. It has elements of infrastructures which are based on OWIN such as hosts and servers, but it has also its own unique components and functions, like authentication. It uses frameworks like SignalR, Nancy, and ASP.NET Web API.
OWIN's Katana Project has 2 main goals:
- Portability - OWIN components should be easily added, removed or swapped out for a new one if we need it. Because of it, we can use third party frameworks on Microsoft's server, while Microsoft frameworks can be used on third party servers
- Modularity - In contrast to frameworks where most options are enabled by default, Katana is focused on creating the simplest and the smallest components. It gives more control to developers over which components they want to use.
Why MVC doesn't work on OWIN (at least right now)
Unfortunately, MVC doesn't work on OWIN, because ASP.NET MVC is strictly dependent on System.Web, which is in conflict with OWIN's specification. In the future (ASP.NET vNext) this problem should be resolved by removing System.Web (creating unification of MVC with Web.API).
For more guesses and news articles about OWIN's future, take a look at some of the resources we've gathered here:
- http://stackoverflow.com/questions/21308585/when-should-i-use-owin-katana
- http://stackoverflow.com/questions/28307138/asp-net-vnext-and-owin
- http://stackoverflow.com/questions/25478451/owin-self-host-asp-net-mvc
- http://www.typecastexception.com/post/2015/01/04/ASPNET-Understanding-OWIN-Katana-and-the-Middleware-Pipeline.aspx#What-is-OWIN--and-Why-Do-I-Care-
- http://stackoverflow.com/questions/22238424/run-asp-net-mvc-as-owin-middleware
Supported components
Supported servers:
- nginx[1]
- iis
Supported frameworks:
- Nancy
- SignalR
- WebApi
- FubuMVC
- Simple.Web
- DuoVia.Http
- ACSP.NET
Alternatives
NancyFx is an alternative for MVC. It is a framework that is compatible with OWIN. However NancyFx has got less tool support and created apps than MVC.
Tutorials
Articles and app examples that describe OWIN and Katana:
- http://www.codeproject.com/Articles/826757/Understanding-OWIN-and-Katana
- http://typecastexception.com/post/2015/01/04/ASPNET-Understanding-OWIN-Katana-and-the-Middleware-Pipeline.aspx#What-is-OWIN--and-Why-Do-I-Care-
- http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api
- http://www.asp.net/aspnet/overview/owin-and-katana/getting-started-with-owin-and-katana
- http://dotnetcodr.com/2014/04/14/owin-and-katana-part-1-the-basics/
- http://blog.jsinh.in/hosting-asp-net-5-web-application-on-linux/#.VYKRb_ntmkq
- https://msdn.microsoft.com/en-us/magazine/dn451439.aspx
- https://github.com/i4004/AcspNet
- http://aspnet.codeplex.com/SourceControl/latest#Samples/Katana/AspNetRoutes/ReadMe.txt
- https://iobservable.net/blog/2013/08/01/owin-and-nginx/
Sources:
- http://keyoti.com/blog/asp-net-v5web-apivnextowin-a-beginners-primer-part-1/
- http://benfoster.io/blog/nancy-vs-aspnet-mvc-getting-started
- http://davidfowl.com/asp-net-vnext/
- https://pl.wikipedia.org
- http://www.codeproject.com/Articles/826757/Understanding-OWIN-and-Katana
- http://stackoverflow.com/questions/20524060/how-to-explain-katana-and-owin-in-simple-words-and-uses
- http://typecastexception.com/post/2015/01/04/ASPNET-Understanding-OWIN-Katana-and-the-Middleware-Pipeline.aspx