#20 - Add Use extension for inline middleware.
This commit is contained in:
parent
5557b959c4
commit
98f4212915
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNet
|
||||
{
|
||||
public static class UseExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Use middleware defined in-line.
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="middleware">A function that handles the request or calls the given next function.</param>
|
||||
/// <returns></returns>
|
||||
public static IBuilder Use(this IBuilder app, Func<HttpContext, Func<Task>, Task> middleware)
|
||||
{
|
||||
return app.Use(next =>
|
||||
{
|
||||
return context =>
|
||||
{
|
||||
Func<Task> simpleNext = () => next(context);
|
||||
return middleware(context, simpleNext);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
<Compile Include="Extensions\MapWhenMiddleware.cs" />
|
||||
<Compile Include="Extensions\MapWhenOptions.cs" />
|
||||
<Compile Include="Extensions\RunExtensions.cs" />
|
||||
<Compile Include="Extensions\UseExtensions.cs" />
|
||||
<Compile Include="HostString.cs" />
|
||||
<Compile Include="HttpContext.cs" />
|
||||
<Compile Include="HttpRequest.cs" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue