This repository has been archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
130 additions
and
902 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
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
14 changes: 8 additions & 6 deletions
14
src/Convey.CQRS.Commands/src/Convey.CQRS.Commands/Dispatchers/CommandDispatcher.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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Convey.CQRS.Commands.Dispatchers; | ||
|
||
internal sealed class CommandDispatcher : ICommandDispatcher | ||
{ | ||
private readonly IServiceScopeFactory _serviceFactory; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public CommandDispatcher(IServiceScopeFactory serviceFactory) | ||
public CommandDispatcher(IServiceProvider serviceProvider) | ||
{ | ||
_serviceFactory = serviceFactory; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public async Task SendAsync<T>(T command) where T : class, ICommand | ||
public async Task SendAsync<T>(T command, CancellationToken cancellationToken = default) where T : class, ICommand | ||
{ | ||
using var scope = _serviceFactory.CreateScope(); | ||
using var scope = _serviceProvider.CreateScope(); | ||
var handler = scope.ServiceProvider.GetRequiredService<ICommandHandler<T>>(); | ||
await handler.HandleAsync(command); | ||
await handler.HandleAsync(command, cancellationToken); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/Convey.CQRS.Commands/src/Convey.CQRS.Commands/ICommandDispatcher.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Convey.CQRS.Commands; | ||
|
||
public interface ICommandDispatcher | ||
{ | ||
Task SendAsync<T>(T command) where T : class, ICommand; | ||
Task SendAsync<T>(T command, CancellationToken cancellationToken = default) where T : class, ICommand; | ||
} |
3 changes: 2 additions & 1 deletion
3
src/Convey.CQRS.Commands/src/Convey.CQRS.Commands/ICommandHandler.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Convey.CQRS.Commands; | ||
|
||
public interface ICommandHandler<in TCommand> where TCommand : class, ICommand | ||
{ | ||
Task HandleAsync(TCommand command); | ||
Task HandleAsync(TCommand command, CancellationToken cancellationToken = default); | ||
} |
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
14 changes: 8 additions & 6 deletions
14
src/Convey.CQRS.Events/src/Convey.CQRS.Events/Dispatchers/EventDispatcher.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 |
---|---|---|
@@ -1,24 +1,26 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Convey.CQRS.Events.Dispatchers; | ||
|
||
internal sealed class EventDispatcher : IEventDispatcher | ||
{ | ||
private readonly IServiceScopeFactory _serviceFactory; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public EventDispatcher(IServiceScopeFactory serviceFactory) | ||
public EventDispatcher(IServiceProvider serviceProvider) | ||
{ | ||
_serviceFactory = serviceFactory; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public async Task PublishAsync<T>(T @event) where T : class, IEvent | ||
public async Task PublishAsync<T>(T @event, CancellationToken cancellationToken = default) where T : class, IEvent | ||
{ | ||
using var scope = _serviceFactory.CreateScope(); | ||
using var scope = _serviceProvider.CreateScope(); | ||
var handlers = scope.ServiceProvider.GetServices<IEventHandler<T>>(); | ||
foreach (var handler in handlers) | ||
{ | ||
await handler.HandleAsync(@event); | ||
await handler.HandleAsync(@event, cancellationToken); | ||
} | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/Convey.CQRS.Events/src/Convey.CQRS.Events/IEventDispatcher.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Convey.CQRS.Events; | ||
|
||
public interface IEventDispatcher | ||
{ | ||
Task PublishAsync<T>(T @event) where T : class, IEvent; | ||
Task PublishAsync<T>(T @event, CancellationToken cancellationToken = default) where T : class, IEvent; | ||
} |
3 changes: 2 additions & 1 deletion
3
src/Convey.CQRS.Events/src/Convey.CQRS.Events/IEventHandler.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Convey.CQRS.Events; | ||
|
||
public interface IEventHandler<in TEvent> where TEvent : class, IEvent | ||
{ | ||
Task HandleAsync(TEvent @event); | ||
Task HandleAsync(TEvent @event, CancellationToken cancellationToken = default); | ||
} |
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
21 changes: 12 additions & 9 deletions
21
src/Convey.CQRS.Queries/src/Convey.CQRS.Queries/Dispatchers/QueryDispatcher.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 |
---|---|---|
@@ -1,32 +1,35 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Convey.CQRS.Queries.Dispatchers; | ||
|
||
internal sealed class QueryDispatcher : IQueryDispatcher | ||
{ | ||
private readonly IServiceScopeFactory _serviceFactory; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public QueryDispatcher(IServiceScopeFactory serviceFactory) | ||
public QueryDispatcher(IServiceProvider serviceProvider) | ||
{ | ||
_serviceFactory = serviceFactory; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public async Task<TResult> QueryAsync<TResult>(IQuery<TResult> query) | ||
public async Task<TResult> QueryAsync<TResult>(IQuery<TResult> query, CancellationToken cancellationToken = default) | ||
{ | ||
using var scope = _serviceFactory.CreateScope(); | ||
using var scope = _serviceProvider.CreateScope(); | ||
var handlerType = typeof(IQueryHandler<,>).MakeGenericType(query.GetType(), typeof(TResult)); | ||
var handler = scope.ServiceProvider.GetRequiredService(handlerType); | ||
// ReSharper disable once PossibleNullReferenceException | ||
return await (Task<TResult>) handlerType | ||
.GetMethod(nameof(IQueryHandler<IQuery<TResult>, TResult>.HandleAsync))? | ||
.Invoke(handler, new object[] {query}); | ||
.Invoke(handler, new object[] {query, cancellationToken}); | ||
} | ||
|
||
public async Task<TResult> QueryAsync<TQuery, TResult>(TQuery query) where TQuery : class, IQuery<TResult> | ||
public async Task<TResult> QueryAsync<TQuery, TResult>(TQuery query, CancellationToken cancellationToken = default) | ||
where TQuery : class, IQuery<TResult> | ||
{ | ||
using var scope = _serviceFactory.CreateScope(); | ||
using var scope = _serviceProvider.CreateScope(); | ||
var handler = scope.ServiceProvider.GetRequiredService<IQueryHandler<TQuery, TResult>>(); | ||
return await handler.HandleAsync(query); | ||
return await handler.HandleAsync(query, cancellationToken); | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
src/Convey.CQRS.Queries/src/Convey.CQRS.Queries/IQueryDispatcher.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Convey.CQRS.Queries; | ||
|
||
public interface IQueryDispatcher | ||
{ | ||
Task<TResult> QueryAsync<TResult>(IQuery<TResult> query); | ||
Task<TResult> QueryAsync<TQuery, TResult>(TQuery query) where TQuery : class, IQuery<TResult>; | ||
Task<TResult> QueryAsync<TResult>(IQuery<TResult> query, CancellationToken cancellationToken = default); | ||
|
||
Task<TResult> QueryAsync<TQuery, TResult>(TQuery query, CancellationToken cancellationToken = default) | ||
where TQuery : class, IQuery<TResult>; | ||
} |
3 changes: 2 additions & 1 deletion
3
src/Convey.CQRS.Queries/src/Convey.CQRS.Queries/IQueryHandler.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Convey.CQRS.Queries; | ||
|
||
public interface IQueryHandler<in TQuery,TResult> where TQuery : class, IQuery<TResult> | ||
{ | ||
Task<TResult> HandleAsync(TQuery query); | ||
Task<TResult> HandleAsync(TQuery query, CancellationToken cancellationToken = default); | ||
} |
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
Oops, something went wrong.