是Microsoft.Owin类型,如OwinMiddleware和IOwinContext与其他Owin服务器不兼容? [英] Are Microsoft.Owin types like OwinMiddleware and IOwinContext incompatible with other Owin servers?

查看:647
本文介绍了是Microsoft.Owin类型,如OwinMiddleware和IOwinContext与其他Owin服务器不兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我建立使用Microsoft.Owin类型,如OwinMiddleware和IOwinContext,一个OWIN中间件将我与非Microsoft Owin主机/服务器中间件工作的?我期待在中间件类南希和<一个href=\"https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Owin/Handlers/HubDispatcherHandler.cs\">SignalR他们似乎从<一个非常不同的href=\"http://katanaproject.$c$cplex.com/SourceControl/latest#src/Microsoft.Owin/OwinMiddleware.cs\">OwinMiddleware基类,中间件,如cookie认证中间件和<一个href=\"http://aspnetwebstack.$c$cplex.com/SourceControl/latest#src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs\">WebApi是基于。我读的规格,但我还是不太清楚,如果一个非微软的服务器Owin可以与OwinMiddleware和IOwinContext类型的工作,而不必在Microsoft.Owin的依赖(我猜会破坏Owin的目的)。

If I build an OWIN middleware using Microsoft.Owin types like OwinMiddleware and IOwinContext, would my middleware work with non-Microsoft Owin hosts/servers? I'm looking at the middleware classes for Nancy and SignalR and they seem very different from the OwinMiddleware base class that middlewares like the Cookie authentication middleware and WebApi is based on. I'm reading the spec but I'm still not clear if a non-Microsoft Owin server could work with the OwinMiddleware and IOwinContext type without having a dependency on Microsoft.Owin (which I guess would defeat the purpose of Owin).

推荐答案

如果你用的OwinMiddleware基本类型的中间件,默认情况下它不会与非微软Owin服务器工作。但是它可以制成具有非Microsoft服务器工作(SignalR正常工作与Nowin为例)。

If you build middleware with the OwinMiddleware base type, by default it will not work with non Microsoft Owin servers. But it can be made to work with non Microsoft servers (SignalR works fine with Nowin as an example).

IAppBuilder(的默认实现<一个href=\"https://github.com/owin/owin-hosting/blob/master/src/main/Owin.Builder/AppBuilder.cs\">https://github.com/owin/owin-hosting/blob/master/src/main/Owin.Builder/AppBuilder.cs)已签名转换功能建在这任何人都可以注册在T转换 - > AppFunc和AppFunc - > T.这意味着,你可以混合和匹配中间件在同一管道不同的签名(见<一。 href=\"https://katanaproject.$c$cplex.com/SourceControl/latest#src/Microsoft.Owin/Infrastructure/SignatureConversions.cs\">https://katanaproject.$c$cplex.com/SourceControl/latest#src/Microsoft.Owin/Infrastructure/SignatureConversions.cs 。对于OwinMiddleware如何工作的一个例子),只要这种转换的存在,可以使原始的中间件(如南希)与OwinMiddleware无缝工作要看到这是如何工作的看这里:

The default implementation of IAppBuilder (https://github.com/owin/owin-hosting/blob/master/src/main/Owin.Builder/AppBuilder.cs) has a signature conversion feature built in. This allows anyone to register a conversion from T -> AppFunc and AppFunc -> T. This means that you can mix and match middleware with different signatures in the same pipeline. (see https://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin/Infrastructure/SignatureConversions.cs for an example of how OwinMiddleware works). As long as this conversion exists, you can make "raw" middleware (like nancy) work with OwinMiddleware seamlessly. To see how this works look here:

<一个href=\"https://github.com/owin/owin-hosting/blob/master/src/main/Owin.Builder/AppBuilder.cs#L182\">https://github.com/owin/owin-hosting/blob/master/src/main/Owin.Builder/AppBuilder.cs#L182 (现在,随着爆炸你的大脑......阅读)

https://github.com/owin/owin-hosting/blob/master/src/main/Owin.Builder/AppBuilder.cs#L182 (Now that your brain as exploded... read on)

在SignalR的情况下,我们自动添加代表您的转化率(<一个href=\"https://github.com/SignalR/SignalR/blob/dev/src/Microsoft.AspNet.SignalR.Core/Owin/OwinExtensions.cs#L168\">https://github.com/SignalR/SignalR/blob/dev/src/Microsoft.AspNet.SignalR.Core/Owin/OwinExtensions.cs#L168),但它可以在任何code取决于OwinMiddleware以确保过渡工作来进行。

In the case of SignalR, we automatically add the conversion on your behalf (https://github.com/SignalR/SignalR/blob/dev/src/Microsoft.AspNet.SignalR.Core/Owin/OwinExtensions.cs#L168), but it can be done in any code that depends on OwinMiddleware to make sure the transition works.

如果您使用任何Microsoft.Owin.Hosting来引导你的应用程序,但使用非微软的Web服务器,你会得到免费的转换以​​及(参见使用nowin自述为例https://github.com/Bobris/Nowin/blob/master/README.md).

If you use any of the Microsoft.Owin.Hosting to bootstrap your application but you use a non Microsoft web server, you'll get the conversion for free as well (see the nowin readme for an example https://github.com/Bobris/Nowin/blob/master/README.md).

希望这有助于。

这篇关于是Microsoft.Owin类型,如OwinMiddleware和IOwinContext与其他Owin服务器不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆