Skip to content

Commit

Permalink
IInServerExecutionScope
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Mar 1, 2024
1 parent b5844ed commit f35f2d7
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TenantsController(SignInManager<ApplicationUser> signInManager, IServiceP
public async Task<ActionResult<TenantDTO>> GetTenant()
{
var tenantId = ExecutionContext.TenantId;
TenantDTO tenant = await queryDispatcher.DispatchAsync<GetTenantByID, TenantDTO>(new GetTenantByID { TenantId = tenantId });
TenantDTO tenant = await ExecutionContext.QueryDispatcher.DispatchAsync<GetTenantByID, TenantDTO>(new GetTenantByID { TenantId = tenantId });

return Ok(tenant);
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Shared/Features/CQRS/Command/ICommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Shared.Features.Server.ExecutionContext;
using Shared.Features.Server;

namespace Shared.Features.CQRS.Command
{
public interface ICommandHandler<in TCommand> : IInServerExecutionContextScope where TCommand : ICommand
public interface ICommandHandler<in TCommand> : IInServerExecutionScope where TCommand : ICommand
{
Task HandleAsync(TCommand command, CancellationToken cancellationToken);
}
public interface ICommandHandler<in TCommand, TResult> : IInServerExecutionContextScope where TCommand : ICommand<TResult>
public interface ICommandHandler<in TCommand, TResult> : IInServerExecutionScope where TCommand : ICommand<TResult>
{
Task<TResult> HandleAsync(TCommand command, CancellationToken cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<in TDomainEvent> : IInServerExecutionContextScope where TDomainEvent : IDomainEvent
public interface IDomainEventHandler<in TDomainEvent> : IInServerExecutionScope where TDomainEvent : IDomainEvent
{
Task HandleAsync(TDomainEvent query, CancellationToken cancellation);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<in TIntegrationEvent> : IInServerExecutionContextScope where TIntegrationEvent : IIntegrationEvent
public interface IIntegrationEventHandler<in TIntegrationEvent> : IInServerExecutionScope where TIntegrationEvent : IIntegrationEvent
{
Task HandleAsync(TIntegrationEvent integrationEvent, CancellationToken cancellation);
}
Expand Down
9 changes: 9 additions & 0 deletions Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Shared.Features.Server;

namespace Shared.Features.CQRS.Query
{
public class BaseQueryHandler : IInServerExecutionScope

Check failure on line 5 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

'BaseQueryHandler' does not implement interface member 'IInServerExecutionScope.ExecutionContext'. 'BaseQueryHandler.ExecutionContext' cannot implement 'IInServerExecutionScope.ExecutionContext' because it does not have the matching return type of 'IExecutionContext'.

Check failure on line 5 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

'BaseQueryHandler' does not implement interface member 'IInServerExecutionScope.CommandDispatcher'

Check failure on line 5 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

'BaseQueryHandler' does not implement interface member 'IInServerExecutionScope.QueryDispatcher'

Check failure on line 5 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

'BaseQueryHandler' does not implement interface member 'IInServerExecutionScope.IntegrationEventDispatcher'

Check failure on line 5 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

'BaseQueryHandler' does not implement interface member 'IInServerExecutionScope.DomainEventDispatcher'

Check failure on line 5 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

'BaseQueryHandler' does not implement interface member 'IInServerExecutionScope.ValidationService'
{
public IServerExecutionContext ExecutionContext { get; private set; }

Check failure on line 7 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IServerExecutionContext' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in Source/Shared/Features/CQRS/Query/BaseQueryHandler.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IServerExecutionContext' could not be found (are you missing a using directive or an assembly reference?)
}
}
4 changes: 2 additions & 2 deletions Source/Shared/Features/CQRS/Query/IQueryHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Shared.Features.Server.ExecutionContext;
using Shared.Features.Server;

namespace Shared.Features.CQRS.Query
{
public interface IQueryHandler<in TQuery, TQueryResult> : IInServerExecutionContextScope where TQuery : IQuery<TQueryResult>
public interface IQueryHandler<in TQuery, TQueryResult> : IInServerExecutionScope where TQuery : IQuery<TQueryResult>
{
Task<TQueryResult> HandleAsync(TQuery query, CancellationToken cancellation);
}
Expand Down
8 changes: 3 additions & 5 deletions Source/Shared/Features/Server/BaseController.cs
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 7 in Source/Shared/Features/Server/BaseController.cs

View workflow job for this annotation

GitHub Actions / build

Class 'BaseController' cannot have multiple base classes: 'ControllerBase' and 'InServerExecutionScopeBase'
{
public IExecutionContext ExecutionContext { get; init; }
public IServerExecutionContext ExecutionContext { get; }

Check failure on line 9 in Source/Shared/Features/Server/BaseController.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IServerExecutionContext' could not be found (are you missing a using directive or an assembly reference?)

protected readonly IValidationService validationService;

public BaseController(IServiceProvider serviceProvider)
{
ExecutionContext = serviceProvider.GetRequiredService<IExecutionContext>();
ExecutionContext = serviceProvider.GetRequiredService<IServerExecutionContext>();
validationService = serviceProvider.GetRequiredService<IValidationService>();
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
19 changes: 19 additions & 0 deletions Source/Shared/Features/Server/InServerExecutionScopeBase.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}

0 comments on commit f35f2d7

Please sign in to comment.