From 198c1f69bdbf80c052d347345b9f785caa7a1205 Mon Sep 17 00:00:00 2001 From: Alexanderius Date: Sat, 20 Jan 2024 23:42:27 +0600 Subject: [PATCH] [#227] [add] version controller executors [#227] [edit] split to versioned namespaces [#227] [add] initial v2 executor and factory --- .../Execution/ControllersExecutorTests.cs | 2 +- .../Bootstrapper/BaseBootstrapper.cs | 2 +- .../SimplifyWebRegistrationsOverride.cs | 2 +- .../Execution/ControllerExecutor.cs | 2 +- .../Execution/IVersionedControllerExecutor.cs | 28 ++++++++++ .../Execution/V1/ControllerExecutor.cs | 53 +++++++++++++++++++ .../{Building => V1}/ControllerFactory.cs | 2 +- .../{Building => V1}/IControllerFactory.cs | 2 +- .../Execution/V2/ControllerExecutor.cs | 36 +++++++++++++ .../Execution/V2/IControllerFactory.cs | 22 ++++++++ 10 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 src/Simplify.Web/Core/Controllers/Execution/IVersionedControllerExecutor.cs create mode 100644 src/Simplify.Web/Core/Controllers/Execution/V1/ControllerExecutor.cs rename src/Simplify.Web/Core/Controllers/Execution/{Building => V1}/ControllerFactory.cs (94%) rename src/Simplify.Web/Core/Controllers/Execution/{Building => V1}/IControllerFactory.cs (91%) create mode 100644 src/Simplify.Web/Core/Controllers/Execution/V2/ControllerExecutor.cs create mode 100644 src/Simplify.Web/Core/Controllers/Execution/V2/IControllerFactory.cs diff --git a/src/Simplify.Web.Tests/Core/Controllers/Execution/ControllersExecutorTests.cs b/src/Simplify.Web.Tests/Core/Controllers/Execution/ControllersExecutorTests.cs index 8f3d444b..d82162f9 100644 --- a/src/Simplify.Web.Tests/Core/Controllers/Execution/ControllersExecutorTests.cs +++ b/src/Simplify.Web.Tests/Core/Controllers/Execution/ControllersExecutorTests.cs @@ -6,7 +6,7 @@ using NUnit.Framework; using Simplify.DI; using Simplify.Web.Core.Controllers.Execution; -using Simplify.Web.Core.Controllers.Execution.Building; +using Simplify.Web.Core.Controllers.Execution.V1; using Simplify.Web.Meta; using Simplify.Web.Tests.TestEntities; diff --git a/src/Simplify.Web/Bootstrapper/BaseBootstrapper.cs b/src/Simplify.Web/Bootstrapper/BaseBootstrapper.cs index cf3b9050..f836eced 100644 --- a/src/Simplify.Web/Bootstrapper/BaseBootstrapper.cs +++ b/src/Simplify.Web/Bootstrapper/BaseBootstrapper.cs @@ -6,7 +6,7 @@ using Simplify.Web.Core; using Simplify.Web.Core.Controllers; using Simplify.Web.Core.Controllers.Execution; -using Simplify.Web.Core.Controllers.Execution.Building; +using Simplify.Web.Core.Controllers.Execution.V1; using Simplify.Web.Core.PageAssembly; using Simplify.Web.Core.StaticFiles; using Simplify.Web.Core.Views; diff --git a/src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationsOverride.cs b/src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationsOverride.cs index 46963f2a..64a3e24c 100644 --- a/src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationsOverride.cs +++ b/src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationsOverride.cs @@ -6,7 +6,7 @@ using Simplify.Web.Core; using Simplify.Web.Core.Controllers; using Simplify.Web.Core.Controllers.Execution; -using Simplify.Web.Core.Controllers.Execution.Building; +using Simplify.Web.Core.Controllers.Execution.V1; using Simplify.Web.Core.PageAssembly; using Simplify.Web.Core.StaticFiles; using Simplify.Web.Core.Views; diff --git a/src/Simplify.Web/Core/Controllers/Execution/ControllerExecutor.cs b/src/Simplify.Web/Core/Controllers/Execution/ControllerExecutor.cs index 5d6855c8..a937c668 100644 --- a/src/Simplify.Web/Core/Controllers/Execution/ControllerExecutor.cs +++ b/src/Simplify.Web/Core/Controllers/Execution/ControllerExecutor.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Simplify.DI; -using Simplify.Web.Core.Controllers.Execution.Building; +using Simplify.Web.Core.Controllers.Execution.V1; using Simplify.Web.Meta; namespace Simplify.Web.Core.Controllers.Execution; diff --git a/src/Simplify.Web/Core/Controllers/Execution/IVersionedControllerExecutor.cs b/src/Simplify.Web/Core/Controllers/Execution/IVersionedControllerExecutor.cs new file mode 100644 index 00000000..9e792be2 --- /dev/null +++ b/src/Simplify.Web/Core/Controllers/Execution/IVersionedControllerExecutor.cs @@ -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; + +/// +/// Represent versioned controller executor, handles creation and execution of controllers +/// +public interface IVersionedControllerExecutor +{ + /// + /// Gets the controller version + /// + public short Version { get; } + + /// + /// Creates and executes the specified controller. + /// + /// The controller meta-data. + /// The DI container resolver. + /// The context. + /// The route parameters. + Task Execute(IControllerMetaData controllerMetaData, IDIResolver resolver, HttpContext context, + IDictionary? routeParameters = null); +} \ No newline at end of file diff --git a/src/Simplify.Web/Core/Controllers/Execution/V1/ControllerExecutor.cs b/src/Simplify.Web/Core/Controllers/Execution/V1/ControllerExecutor.cs new file mode 100644 index 00000000..77ef3d93 --- /dev/null +++ b/src/Simplify.Web/Core/Controllers/Execution/V1/ControllerExecutor.cs @@ -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; + +/// +/// Provides v1 controllers executor +/// +/// The controller factory. +public class ControllerExecutor1(IControllerFactory controllerFactory) : IVersionedControllerExecutor +{ + private readonly IControllerFactory _controllerFactory = controllerFactory; + + /// + /// Gets the controller version + /// + public short Version => 1; + + /// + /// Creates and executes the specified controller. + /// + /// Type of the controller. + /// The DI container resolver. + /// The context. + /// The route parameters. + /// + public async Task Execute(IControllerMetaData controllerMetaData, IDIResolver resolver, HttpContext context, + IDictionary? 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; + } +} \ No newline at end of file diff --git a/src/Simplify.Web/Core/Controllers/Execution/Building/ControllerFactory.cs b/src/Simplify.Web/Core/Controllers/Execution/V1/ControllerFactory.cs similarity index 94% rename from src/Simplify.Web/Core/Controllers/Execution/Building/ControllerFactory.cs rename to src/Simplify.Web/Core/Controllers/Execution/V1/ControllerFactory.cs index 02957fc6..ad28f62a 100644 --- a/src/Simplify.Web/Core/Controllers/Execution/Building/ControllerFactory.cs +++ b/src/Simplify.Web/Core/Controllers/Execution/V1/ControllerFactory.cs @@ -4,7 +4,7 @@ using Simplify.DI; using Simplify.Web.Core.AccessorsBuilding; -namespace Simplify.Web.Core.Controllers.Execution.Building; +namespace Simplify.Web.Core.Controllers.Execution.V1; /// /// Controller factory diff --git a/src/Simplify.Web/Core/Controllers/Execution/Building/IControllerFactory.cs b/src/Simplify.Web/Core/Controllers/Execution/V1/IControllerFactory.cs similarity index 91% rename from src/Simplify.Web/Core/Controllers/Execution/Building/IControllerFactory.cs rename to src/Simplify.Web/Core/Controllers/Execution/V1/IControllerFactory.cs index edd4bc60..574ef375 100644 --- a/src/Simplify.Web/Core/Controllers/Execution/Building/IControllerFactory.cs +++ b/src/Simplify.Web/Core/Controllers/Execution/V1/IControllerFactory.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Http; using Simplify.DI; -namespace Simplify.Web.Core.Controllers.Execution.Building; +namespace Simplify.Web.Core.Controllers.Execution.V1; /// /// Represent controller factory diff --git a/src/Simplify.Web/Core/Controllers/Execution/V2/ControllerExecutor.cs b/src/Simplify.Web/Core/Controllers/Execution/V2/ControllerExecutor.cs new file mode 100644 index 00000000..f9060138 --- /dev/null +++ b/src/Simplify.Web/Core/Controllers/Execution/V2/ControllerExecutor.cs @@ -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; + +/// +/// Provides v1 controllers executor +/// +/// The controller factory. +public class ControllerExecutor2(IControllerFactory controllerFactory) : IVersionedControllerExecutor +{ + private readonly IControllerFactory _controllerFactory = controllerFactory; + + /// + /// Gets the controller version + /// + public short Version => 1; + + /// + /// Creates and executes the specified controller. + /// + /// Type of the controller. + /// The DI container resolver. + /// The context. + /// The route parameters. + /// + public Task Execute(IControllerMetaData controllerMetaData, IDIResolver resolver, HttpContext context, + IDictionary? routeParameters = null) + { + throw new NotImplementedException(); + } +} diff --git a/src/Simplify.Web/Core/Controllers/Execution/V2/IControllerFactory.cs b/src/Simplify.Web/Core/Controllers/Execution/V2/IControllerFactory.cs new file mode 100644 index 00000000..f902fc2c --- /dev/null +++ b/src/Simplify.Web/Core/Controllers/Execution/V2/IControllerFactory.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Http; +using Simplify.DI; + +namespace Simplify.Web.Core.Controllers.Execution.V2; + +/// +/// Represent controller factory +/// +public interface IControllerFactory +{ + /// + /// Creates the controller. + /// + /// Type of the controller. + /// The DI container resolver. + /// The context. + /// The route parameters. + /// + ResponseShortcutsControllerBase CreateController(Type controllerType, IDIResolver resolver, HttpContext context, IDictionary? routeParameters = null); +} \ No newline at end of file