Skip to content

Commit

Permalink
[#227] [add] version controller executors
Browse files Browse the repository at this point in the history
[#227] [edit] split to versioned namespaces
[#227] [add] initial v2 executor and factory
  • Loading branch information
i4004 committed Jan 20, 2024
1 parent 696f07c commit 198c1f6
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Simplify.Web/Bootstrapper/BaseBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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);
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Controller factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Represent controller factory
Expand Down
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();
}
}
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);
}

0 comments on commit 198c1f6

Please sign in to comment.