diff --git a/Source/Modules/TenantIdentity/Web/Server/Controllers/Aggregates/TenantsController.cs b/Source/Modules/TenantIdentity/Web/Server/Controllers/Aggregates/TenantsController.cs index 4047e522..715dd565 100644 --- a/Source/Modules/TenantIdentity/Web/Server/Controllers/Aggregates/TenantsController.cs +++ b/Source/Modules/TenantIdentity/Web/Server/Controllers/Aggregates/TenantsController.cs @@ -32,7 +32,7 @@ public TenantsController(SignInManager signInManager, IServiceP public async Task> GetTenant() { var tenantId = ExecutionContext.TenantId; - TenantDTO tenant = await queryDispatcher.DispatchAsync(new GetTenantByID { TenantId = tenantId }); + TenantDTO tenant = await ExecutionContext.QueryDispatcher.DispatchAsync(new GetTenantByID { TenantId = tenantId }); return Ok(tenant); } diff --git a/Source/Shared/Features/CQRS/Command/ICommandHandler.cs b/Source/Shared/Features/CQRS/Command/ICommandHandler.cs index b31f59b2..2ffec535 100644 --- a/Source/Shared/Features/CQRS/Command/ICommandHandler.cs +++ b/Source/Shared/Features/CQRS/Command/ICommandHandler.cs @@ -1,12 +1,12 @@ -using Shared.Features.Server.ExecutionContext; +using Shared.Features.Server; namespace Shared.Features.CQRS.Command { - public interface ICommandHandler : IInServerExecutionContextScope where TCommand : ICommand + public interface ICommandHandler : IInServerExecutionScope where TCommand : ICommand { Task HandleAsync(TCommand command, CancellationToken cancellationToken); } - public interface ICommandHandler : IInServerExecutionContextScope where TCommand : ICommand + public interface ICommandHandler : IInServerExecutionScope where TCommand : ICommand { Task HandleAsync(TCommand command, CancellationToken cancellationToken); } diff --git a/Source/Shared/Features/CQRS/DomainEvent/IDomainEventHandler.cs b/Source/Shared/Features/CQRS/DomainEvent/IDomainEventHandler.cs index f0c69459..23dbf666 100644 --- a/Source/Shared/Features/CQRS/DomainEvent/IDomainEventHandler.cs +++ b/Source/Shared/Features/CQRS/DomainEvent/IDomainEventHandler.cs @@ -1,9 +1,9 @@ using Shared.Features.Domain; -using Shared.Features.Server.ExecutionContext; +using Shared.Features.Server; namespace Shared.Features.CQRS.DomainEvent { - public interface IDomainEventHandler : IInServerExecutionContextScope where TDomainEvent : IDomainEvent + public interface IDomainEventHandler : IInServerExecutionScope where TDomainEvent : IDomainEvent { Task HandleAsync(TDomainEvent query, CancellationToken cancellation); } diff --git a/Source/Shared/Features/CQRS/IntegrationEvent/IIntegrationEventHandler.cs b/Source/Shared/Features/CQRS/IntegrationEvent/IIntegrationEventHandler.cs index 4ab8a91f..f43c381a 100644 --- a/Source/Shared/Features/CQRS/IntegrationEvent/IIntegrationEventHandler.cs +++ b/Source/Shared/Features/CQRS/IntegrationEvent/IIntegrationEventHandler.cs @@ -1,9 +1,9 @@ -using Shared.Features.Server.ExecutionContext; +using Shared.Features.Server; using Shared.Kernel.BuildingBlocks; namespace Shared.Features.CQRS.IntegrationEvent { - public interface IIntegrationEventHandler : IInServerExecutionContextScope where TIntegrationEvent : IIntegrationEvent + public interface IIntegrationEventHandler : IInServerExecutionScope where TIntegrationEvent : IIntegrationEvent { Task HandleAsync(TIntegrationEvent integrationEvent, CancellationToken cancellation); } diff --git a/Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs b/Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs new file mode 100644 index 00000000..9617911b --- /dev/null +++ b/Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs @@ -0,0 +1,9 @@ +using Shared.Features.Server; + +namespace Shared.Features.CQRS.Query +{ + public class BaseQueryHandler : IInServerExecutionScope + { + public IServerExecutionContext ExecutionContext { get; private set; } + } +} diff --git a/Source/Shared/Features/CQRS/Query/IQueryHandler.cs b/Source/Shared/Features/CQRS/Query/IQueryHandler.cs index e64403b6..30d1c797 100644 --- a/Source/Shared/Features/CQRS/Query/IQueryHandler.cs +++ b/Source/Shared/Features/CQRS/Query/IQueryHandler.cs @@ -1,8 +1,8 @@ -using Shared.Features.Server.ExecutionContext; +using Shared.Features.Server; namespace Shared.Features.CQRS.Query { - public interface IQueryHandler : IInServerExecutionContextScope where TQuery : IQuery + public interface IQueryHandler : IInServerExecutionScope where TQuery : IQuery { Task HandleAsync(TQuery query, CancellationToken cancellation); } diff --git a/Source/Shared/Features/Server/BaseController.cs b/Source/Shared/Features/Server/BaseController.cs index 91b1a036..e59aade7 100644 --- a/Source/Shared/Features/Server/BaseController.cs +++ b/Source/Shared/Features/Server/BaseController.cs @@ -1,20 +1,18 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Shared.Features.Server.ExecutionContext; -using Shared.Kernel.BuildingBlocks; using Shared.Kernel.BuildingBlocks.ModelValidation; namespace Shared.Features.Server { - public class BaseController : ControllerBase, IInServerExecutionContextScope + public class BaseController : ControllerBase, InServerExecutionScopeBase { - public IExecutionContext ExecutionContext { get; init; } + public IServerExecutionContext ExecutionContext { get; } protected readonly IValidationService validationService; public BaseController(IServiceProvider serviceProvider) { - ExecutionContext = serviceProvider.GetRequiredService(); + ExecutionContext = serviceProvider.GetRequiredService(); validationService = serviceProvider.GetRequiredService(); } } diff --git a/Source/Shared/Features/Server/ExecutionContext/IInServerExecutionContextScope.cs b/Source/Shared/Features/Server/ExecutionContext/IInServerExecutionContextScope.cs deleted file mode 100644 index 27de5af3..00000000 --- a/Source/Shared/Features/Server/ExecutionContext/IInServerExecutionContextScope.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Shared.Kernel.BuildingBlocks; - -namespace Shared.Features.Server.ExecutionContext -{ - public interface IInServerExecutionContextScope - { - public IExecutionContext ExecutionContext { get; init; } - } -} diff --git a/Source/Shared/Features/Server/ExecutionContext/ServerExecutionContext.cs b/Source/Shared/Features/Server/ExecutionContext/ServerExecutionContext.cs index a36babdf..9a4b672e 100644 --- a/Source/Shared/Features/Server/ExecutionContext/ServerExecutionContext.cs +++ b/Source/Shared/Features/Server/ExecutionContext/ServerExecutionContext.cs @@ -7,12 +7,13 @@ using Shared.Features.CQRS.DomainEvent; using Shared.Features.CQRS.IntegrationEvent; using Shared.Features.CQRS.Query; +using Shared.Kernel.BuildingBlocks; using Shared.Kernel.BuildingBlocks.Auth; using Shared.Kernel.Extensions.ClaimsPrincipal; namespace Shared.Features.Server.ExecutionContext { - public class ServerExecutionContext : IServerExecutionContext + public class ServerExecutionContext : IExecutionContext { private static ServerExecutionContext executionContext; private ServerExecutionContext() { } @@ -24,10 +25,6 @@ private ServerExecutionContext() { } public TenantRole TenantRole { get; private set; } public IHostEnvironment HostingEnvironment { get; set; } public Uri BaseURI { get; private set; } - public ICommandDispatcher CommandDispatcher { get; private set; } - public IQueryDispatcher QueryDispatcher { get; private set; } - public IIntegrationEventDispatcher IntegrationEventDispatcher { get; private set; } - public IDomainEventDispatcher DomainEventDispatcher { get; private set; } public static ServerExecutionContext CreateInstance(IServiceProvider serviceProvider) { diff --git a/Source/Shared/Features/Server/ExecutionContext/IServerExecutionContext.cs b/Source/Shared/Features/Server/IInServerExecutionScope.cs similarity index 65% rename from Source/Shared/Features/Server/ExecutionContext/IServerExecutionContext.cs rename to Source/Shared/Features/Server/IInServerExecutionScope.cs index 0f3c1f56..4b77c915 100644 --- a/Source/Shared/Features/Server/ExecutionContext/IServerExecutionContext.cs +++ b/Source/Shared/Features/Server/IInServerExecutionScope.cs @@ -3,14 +3,17 @@ using Shared.Features.CQRS.IntegrationEvent; using Shared.Features.CQRS.Query; using Shared.Kernel.BuildingBlocks; +using Shared.Kernel.BuildingBlocks.ModelValidation; -namespace Shared.Features.Server.ExecutionContext +namespace Shared.Features.Server { - public interface IServerExecutionContext : IExecutionContext + public interface IInServerExecutionScope { + public IExecutionContext ExecutionContext { get; } public ICommandDispatcher CommandDispatcher { get; } public IQueryDispatcher QueryDispatcher { get; } public IIntegrationEventDispatcher IntegrationEventDispatcher { get; } public IDomainEventDispatcher DomainEventDispatcher { get; } + public IValidationService ValidationService { get; } } } diff --git a/Source/Shared/Features/Server/InServerExecutionScopeBase.cs b/Source/Shared/Features/Server/InServerExecutionScopeBase.cs new file mode 100644 index 00000000..5bc7b8ce --- /dev/null +++ b/Source/Shared/Features/Server/InServerExecutionScopeBase.cs @@ -0,0 +1,19 @@ +using Shared.Features.CQRS.Command; +using Shared.Features.CQRS.DomainEvent; +using Shared.Features.CQRS.IntegrationEvent; +using Shared.Features.CQRS.Query; +using Shared.Kernel.BuildingBlocks; +using Shared.Kernel.BuildingBlocks.ModelValidation; + +namespace Shared.Features.Server +{ + public class InServerExecutionScopeBase : IInServerExecutionScope + { + public IExecutionContext ExecutionContext { get; private set; } + public ICommandDispatcher CommandDispatcher { get; private set; } + public IQueryDispatcher QueryDispatcher { get; private set; } + public IIntegrationEventDispatcher IntegrationEventDispatcher { get; private set; } + public IDomainEventDispatcher DomainEventDispatcher { get; private set; } + public IValidationService ValidationService { get; private set; } + } +}