ASP.NET Core middleware or OWIN middleware?
Asked Answered
E

2

34

As I understand it, ASP.NET Core has support for OWIN middleware (via app.UseOwin()) in addition to its own native middleware.

What is the difference between ASP.NET Core middleware and OWIN middleware?

When designing a new middleware, how do I know if I should design it as a ASP.NET Core middleware or a OWIN middleware?

Empress answered 10/9, 2016 at 18:11 Comment(0)
L
34

Your question made me curious and I would like to share, what I have learned so far.

Katana is the implementation of the OWIN spec. After version 3.0 of Katana this technology has been fully integration in the web stack we know as ASP.NET Core today.

While this transition much has stayed similar to the OWIN specifications. Although some changes have been made. In order to use existing OWIN middleware in ASP.NET Core the supports OWIN by an optional feature ("app.UseOwin()").

If you want to target with your middleware ASP.NET apps and ASP.NET core apps, then I would use OWIN middleware. If you want to give ASP.NET Core developers a first class citizen experience, then a ASP.NET Core middleware would be recognized as more "fitting".

Some information about the relationship between ASP.NET Core middleware and OWIN middleware can be found here:

Livre answered 11/9, 2016 at 10:35 Comment(0)
E
7

I have come to understand it as this; ASP.NET Core middleware is on a higher level than OWIN middleware which is on a lower level.

ASP.NET Core middleware has the advantage that it is much easier to develop a middleware in as you get passed in the HttpContext which you can use. The disadvantage is that the middleware you develop depends on ASP.NET Core.

OWIN is on a lower level and you get a OWIN environment which is a IDictionary<string, object>. The advantage is that is it not tied to ASP.NET hence can run on any OWIN server (such as Nowin). The disadvantage is that it takes more effort to code since you have to build your own context from the OWIN environment or use the OWIN environment dictionary directly and keep track of all OWIN keys and objects.

Edit: You don't have to keep track of OWIN keys yourself, you can use the OwinEnvironment class to get a strongly typed environment.

var environment = new OwinEnvironment(HttpContext);
var features = new OwinFeatureCollection(environment);
Empress answered 27/9, 2016 at 12:25 Comment(1)
Mark. OwinEnvironment is a concept from Microsoft.AspNetCore.Owin , and not a pure OWIN thing. Similar to that OwinMiddleware is a Katana thing, and not a pure OWIN thing.Erlineerlinna

© 2022 - 2024 — McMap. All rights reserved.