OWIN详细介绍

1.OWIN.dll介绍

用反编译工具打开Owin.dll,你会发现类库中就只有一个IAppBuilder接口,所以说OWIN是针对.NET平台的开放Web接口。

public interface IAppBuilder
{
IDictionary Properties
{
get;
}
IAppBuilder Use(object middleware, params object[] args);
object Build(Type returnType);
IAppBuilder New();
}

2.Microsoft.Owin.dll
Microsoft.Owin.dll是微软对Owin的具体实现,其中就包括"中间件"。下文将使用代码描述自定义基于Owin的"中间件"。

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;

namespace Microsoft.Owin
{
/// <summary>
/// An abstract base class for a standard middleware pattern.
/// </summary>
public abstract class OwinMiddleware
{
/// <summary>
/// Instantiates the middleware with an optional pointer to the next component.
/// </summary>
/// <param name="next"></param>
protected OwinMiddleware(OwinMiddleware next)
{
Next = next;
}

/// <summary>
/// The optional next component.
/// </summary>
protected OwinMiddleware Next { get; set; }

/// <summary>
/// Process an individual request.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public abstract Task Invoke(IOwinContext context);
}
}

Next是下一步处理用到的中间件。
自定义的中间件主要是重写Invoke来实现自己的功能需求。

猜你喜欢

转载自www.cnblogs.com/zkb9604/p/11529111.html