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
{
/// 
/// An abstract base class for a standard middleware pattern.
/// 
public abstract class OwinMiddleware
{
/// 
/// Instantiates the middleware with an optional pointer to the next component.
/// 
/// 
protected OwinMiddleware(OwinMiddleware next)
{
Next = next;
}

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

/// 
/// Process an individual request.
/// 
/// 
/// 
public abstract Task Invoke(IOwinContext context);
}
}

 

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

你可能感兴趣的:(OWIN详细介绍)