-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intial refactoring to intercept regular MVC route requests
- Loading branch information
1 parent
d14911e
commit 3858ecf
Showing
6 changed files
with
174 additions
and
97 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
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
src/ServiceComposer.AspNetCore/CompositionOverControllersActionFilter.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 @@ | ||
#if NETCOREAPP3_1 | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace ServiceComposer.AspNetCore | ||
{ | ||
internal class CompositionOverControllersActionFilter : IAsyncResultFilter | ||
{ | ||
private readonly CompositionOverControllersRoutes _compositionOverControllersRoutes; | ||
|
||
public CompositionOverControllersActionFilter(CompositionOverControllersRoutes compositionOverControllersRoutes) | ||
{ | ||
_compositionOverControllersRoutes = compositionOverControllersRoutes; | ||
} | ||
|
||
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) | ||
{ | ||
var endpoint = context.HttpContext.GetEndpoint() as RouteEndpoint; | ||
var handlerTypes = _compositionOverControllersRoutes.HandlersForRoute(endpoint.RoutePattern.RawText, | ||
context.HttpContext.Request.Method); | ||
if (handlerTypes.Any()) | ||
{ | ||
|
||
} | ||
|
||
await next(); | ||
} | ||
} | ||
} | ||
#endif |
30 changes: 30 additions & 0 deletions
30
src/ServiceComposer.AspNetCore/CompositionOverControllersRoutes.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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ServiceComposer.AspNetCore | ||
{ | ||
internal class CompositionOverControllersRoutes | ||
{ | ||
private Dictionary<string, Type[]> _compositionOverControllerGetComponents; | ||
private readonly Type[] empty = new Type[0]; | ||
public void AddGetComponentsSource(Dictionary<string, Type[]> compositionOverControllerGetComponents) | ||
{ | ||
_compositionOverControllerGetComponents = compositionOverControllerGetComponents ?? throw new ArgumentNullException(nameof(compositionOverControllerGetComponents)); | ||
} | ||
|
||
public Type[] HandlersForRoute(string routePatternRawText, string requestMethod) | ||
{ | ||
switch (requestMethod.ToLowerInvariant()) | ||
{ | ||
case "get": | ||
if (_compositionOverControllerGetComponents.ContainsKey(routePatternRawText)) | ||
{ | ||
return _compositionOverControllerGetComponents[routePatternRawText]; | ||
} | ||
break; | ||
} | ||
|
||
return empty; | ||
} | ||
} | ||
} |
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
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