-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#227] [add] version controller executors
- Loading branch information
Showing
10 changed files
with
145 additions
and
6 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
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
28 changes: 28 additions & 0 deletions
28
src/Simplify.Web/Core/Controllers/Execution/IVersionedControllerExecutor.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,28 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Simplify.DI; | ||
using Simplify.Web.Meta; | ||
|
||
namespace Simplify.Web.Core.Controllers.Execution; | ||
|
||
/// <summary> | ||
/// Represent versioned controller executor, handles creation and execution of controllers | ||
/// </summary> | ||
public interface IVersionedControllerExecutor | ||
{ | ||
/// <summary> | ||
/// Gets the controller version | ||
/// </summary> | ||
public short Version { get; } | ||
|
||
/// <summary> | ||
/// Creates and executes the specified controller. | ||
/// </summary> | ||
/// <param name="controllerMetaData">The controller meta-data.</param> | ||
/// <param name="resolver">The DI container resolver.</param> | ||
/// <param name="context">The context.</param> | ||
/// <param name="routeParameters">The route parameters.</param> | ||
Task<ControllerResponse?> Execute(IControllerMetaData controllerMetaData, IDIResolver resolver, HttpContext context, | ||
IDictionary<string, object>? routeParameters = null); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Simplify.Web/Core/Controllers/Execution/V1/ControllerExecutor.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,53 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Simplify.DI; | ||
using Simplify.Web.Meta; | ||
|
||
namespace Simplify.Web.Core.Controllers.Execution.V1; | ||
|
||
/// <summary> | ||
/// Provides v1 controllers executor | ||
/// </summary> | ||
/// <param name="controllerFactory">The controller factory.</param> | ||
public class ControllerExecutor1(IControllerFactory controllerFactory) : IVersionedControllerExecutor | ||
{ | ||
private readonly IControllerFactory _controllerFactory = controllerFactory; | ||
|
||
/// <summary> | ||
/// Gets the controller version | ||
/// </summary> | ||
public short Version => 1; | ||
|
||
/// <summary> | ||
/// Creates and executes the specified controller. | ||
/// </summary> | ||
/// <param name="controllerMetaData">Type of the controller.</param> | ||
/// <param name="resolver">The DI container resolver.</param> | ||
/// <param name="context">The context.</param> | ||
/// <param name="routeParameters">The route parameters.</param> | ||
/// <returns></returns> | ||
public async Task<ControllerResponse?> Execute(IControllerMetaData controllerMetaData, IDIResolver resolver, HttpContext context, | ||
IDictionary<string, object>? routeParameters = null) | ||
{ | ||
ControllerResponse? response = null; | ||
var controller = _controllerFactory.CreateController(controllerMetaData.ControllerType, resolver, context, routeParameters); | ||
|
||
switch (controller) | ||
{ | ||
case SyncControllerBase syncController: | ||
{ | ||
response = syncController.Invoke(); | ||
break; | ||
} | ||
|
||
case AsyncControllerBase asyncController: | ||
{ | ||
response = await asyncController.Invoke(); | ||
break; | ||
} | ||
} | ||
|
||
return response; | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/Simplify.Web/Core/Controllers/Execution/V2/ControllerExecutor.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 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Simplify.DI; | ||
using Simplify.Web.Meta; | ||
|
||
namespace Simplify.Web.Core.Controllers.Execution.V2; | ||
|
||
/// <summary> | ||
/// Provides v1 controllers executor | ||
/// </summary> | ||
/// <param name="controllerFactory">The controller factory.</param> | ||
public class ControllerExecutor2(IControllerFactory controllerFactory) : IVersionedControllerExecutor | ||
{ | ||
private readonly IControllerFactory _controllerFactory = controllerFactory; | ||
|
||
/// <summary> | ||
/// Gets the controller version | ||
/// </summary> | ||
public short Version => 1; | ||
|
||
/// <summary> | ||
/// Creates and executes the specified controller. | ||
/// </summary> | ||
/// <param name="controllerMetaData">Type of the controller.</param> | ||
/// <param name="resolver">The DI container resolver.</param> | ||
/// <param name="context">The context.</param> | ||
/// <param name="routeParameters">The route parameters.</param> | ||
/// <returns></returns> | ||
public Task<ControllerResponse?> Execute(IControllerMetaData controllerMetaData, IDIResolver resolver, HttpContext context, | ||
IDictionary<string, object>? routeParameters = null) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Simplify.Web/Core/Controllers/Execution/V2/IControllerFactory.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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Http; | ||
using Simplify.DI; | ||
|
||
namespace Simplify.Web.Core.Controllers.Execution.V2; | ||
|
||
/// <summary> | ||
/// Represent controller factory | ||
/// </summary> | ||
public interface IControllerFactory | ||
{ | ||
/// <summary> | ||
/// Creates the controller. | ||
/// </summary> | ||
/// <param name="controllerType">Type of the controller.</param> | ||
/// <param name="resolver">The DI container resolver.</param> | ||
/// <param name="context">The context.</param> | ||
/// <param name="routeParameters">The route parameters.</param> | ||
/// <returns></returns> | ||
ResponseShortcutsControllerBase CreateController(Type controllerType, IDIResolver resolver, HttpContext context, IDictionary<string, object>? routeParameters = null); | ||
} |