-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,035 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Solutions/Menes.Hosting.AspNetCore/Menes/Hosting/AspNetCore/HttpContextExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// <copyright file="HttpContextExtensions.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Menes.Hosting.AspNetCore | ||
{ | ||
using System.Threading.Tasks; | ||
|
||
using Menes.Internal; | ||
|
||
using Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Extension methods for HttpContext. | ||
/// </summary> | ||
public static class HttpContextExtensions | ||
{ | ||
/// <summary> | ||
/// Uses the <see cref="IOpenApiHost{HttpRequest, IActionResult}"/> to handle the request. | ||
/// </summary> | ||
/// <param name="host">The host to handle the request.</param> | ||
/// <param name="httpContext">The context for the request to handle.</param> | ||
/// <param name="parameters">Any dynamically constructed parameters sent to the request.</param> | ||
/// <returns>The result of the request.</returns> | ||
public static async Task HandleRequestAsync( | ||
this IOpenApiHost<HttpRequest, IHttpResponseResult> host, HttpContext httpContext, object parameters) | ||
{ | ||
HttpRequest httpRequest = httpContext.Request; | ||
IHttpResponseResult result = await host.HandleRequestAsync(httpRequest.Path, httpRequest.Method, httpRequest, parameters); | ||
await result.ExecuteResultAsync(httpContext.Response); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Solutions/Menes.Hosting.AspNetCore/Menes/Hosting/AspNetCore/MenesCatchAllMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// <copyright file="MenesCatchAllMiddleware.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Menes.Hosting.AspNetCore | ||
{ | ||
using System.Threading.Tasks; | ||
|
||
using Menes.Internal; | ||
|
||
using Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Middleware that passes all requests on to Menes. This never forwards requests further down the pipeline. | ||
/// </summary> | ||
internal class MenesCatchAllMiddleware : IMiddleware | ||
{ | ||
private static readonly object EmptyParameters = new (); | ||
private readonly IOpenApiHost<HttpRequest, IHttpResponseResult> host; | ||
|
||
/// <summary> | ||
/// Creates a <see cref="MenesCatchAllMiddleware"/>. | ||
/// </summary> | ||
/// <param name="host">The Menes host.</param> | ||
public MenesCatchAllMiddleware(IOpenApiHost<HttpRequest, IHttpResponseResult> host) | ||
{ | ||
this.host = host; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task InvokeAsync(HttpContext context, RequestDelegate next) | ||
{ | ||
await this.host.HandleRequestAsync(context, EmptyParameters); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
....Hosting.AspNetCore/Menes/Hosting/AspNetCore/OpenApiAspNetApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// <copyright file="OpenApiAspNetApplicationBuilderExtensions.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Menes.Hosting.AspNetCore | ||
{ | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
/// <summary> | ||
/// Extension methods for adding Menes to an ASP.NET Core pipeline. | ||
/// </summary> | ||
public static class OpenApiAspNetApplicationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds middleware that directs all requests to Menes. | ||
/// </summary> | ||
/// <param name="app">The pipeline builder.</param> | ||
/// <returns>The modified pipeline builder.</returns> | ||
public static IApplicationBuilder UseMenesCatchAll(this IApplicationBuilder app) | ||
{ | ||
return app.UseMiddleware<MenesCatchAllMiddleware>(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Solutions/Menes.Hosting.AspNetCore/Menes/Internal/IHttpResponseResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// <copyright file="IHttpResponseResult.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Menes.Internal | ||
{ | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Populates an <see cref="HttpResponse"/> with the outcome (or failure) of an operation. | ||
/// </summary> | ||
public interface IHttpResponseResult | ||
{ | ||
/// <summary> | ||
/// Populates the response. | ||
/// </summary> | ||
/// <param name="httpResponse">The response to populate.</param> | ||
/// <returns>A task that completes when the response has been populated.</returns> | ||
Task ExecuteResultAsync(HttpResponse httpResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.