但是,我们收到了在mvc5应用程序中使用OWIN中间件组件/包的建议,以获得可插拔架构,性能等的优点.
如果我们在Windows Azure中的IIS上托管的MVC5应用程序中使用OWIN中间件,我想了解如何获得性能提升.我的应用程序会使用owin中间件软件包在IIS管道中跳过许多不必要的事情吗?在IIS上托管的时候,使用OWIN在MVC5中有什么其他好处吗?
解决方法
AppGroup对象是Katana发生“魔术”的地方,因为它是调用组件使用的逻辑,签名是这样的:
Func<IDictionary<string,object>,Task>;
Note: The
IDictionary<string,object>
represents the environment values (such asRequest
andResponse
; thinkHttpContext
in ASP.NET) and the OWIN standard defines certain values that must exist in this dictionary,such as"owin.RequestBody"
or"owin.ResponseBody"
. Katana is Microsoft’s implementation of the OWIN standard and as such has these,and other,dictionary items available out-of-the-Box.
组件的一个例子将是一个匹配AppFunc的签名的方法(它是Func< IDictionary< string,Task>,像这样:
public async Task Invoke(IDictionary<string,object> environment) { // Do processing... // Wait for next component to complete await _nextComponent(environment); // Do more processing... }
Note: OWIN expects the method to return a
Task
or generate an exception,soreturn null;
would be invalid.
那么你怎么知道下一个组件是什么呢?
您的组件的构造函数需要接受Func< IDictionary< string,Task>的参数,如下所示:
public class HelloWorldCOmponent { Func<IDictionary<string,Task> _next; public HelloWorldComponent(Func<IDictionary<string,Task> next) { _next = next; } public async Task Invoke(IDictionary<string,object> environment) { // Do something // Wait for next component to return await _next(environment); } }