-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce tag-based handler filtering through
HandlerTag
and `Handl…
…erTags` attributes
- Loading branch information
Showing
58 changed files
with
947 additions
and
111 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
27 changes: 27 additions & 0 deletions
27
src/LiteBus.Commands.Abstractions/CommandMediationSettings.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace LiteBus.Commands.Abstractions; | ||
|
||
/// <summary> | ||
/// Represents the settings used during command mediation. | ||
/// </summary> | ||
public sealed class CommandMediationSettings | ||
{ | ||
/// <summary> | ||
/// Gets the filters to be applied during command mediation. | ||
/// </summary> | ||
public CommandMediationFilters Filters { get; } = new(); | ||
|
||
/// <summary> | ||
/// Represents the filters to be applied during command mediation. | ||
/// </summary> | ||
public sealed class CommandMediationFilters | ||
{ | ||
/// <summary> | ||
/// Gets or sets the collection of tags used to filter command handlers (i.e., pre, main and post) during mediation. | ||
/// </summary> | ||
public IEnumerable<string> Tags { get; set; } = new List<string>(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/LiteBus.Commands.Abstractions/Exceptions/MultipleCommandHandlerFoundException.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace LiteBus.Commands.Abstractions.Exceptions; | ||
|
||
public sealed class MultipleCommandHandlerFoundException : Exception | ||
{ | ||
public MultipleCommandHandlerFoundException(Type commandType, IEnumerable<Type> handlerTypes) | ||
: base($"Multiple command handler found for command type {commandType.FullName}. " + | ||
$"Handler types: {string.Join(", ", handlerTypes.Select(x => x.FullName))}") | ||
{ | ||
} | ||
} |
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,26 +1,35 @@ | ||
using System.Threading; | ||
#nullable enable | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace LiteBus.Commands.Abstractions; | ||
|
||
/// <summary> | ||
/// Sends commands to their corresponding handlers | ||
/// Represents the mediator interface for sending commands within the application. | ||
/// </summary> | ||
public interface ICommandMediator | ||
{ | ||
/// <summary> | ||
/// Sends a command without result to its corresponding handler | ||
/// Asynchronously sends a command for mediation. | ||
/// </summary> | ||
/// <param name="command">the command to send</param> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns></returns> | ||
Task SendAsync(ICommand command, CancellationToken cancellationToken = default); | ||
/// <param name="command">The command to be sent.</param> | ||
/// <param name="commandMediationSettings">Optional settings for command mediation.</param> | ||
/// <param name="cancellationToken">Cancellation token for the operation.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
Task SendAsync(ICommand command, | ||
CommandMediationSettings? commandMediationSettings = null, | ||
CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Sends a command to its corresponding handler and returns the command result | ||
/// Asynchronously sends a command for mediation and returns a result. | ||
/// </summary> | ||
/// <param name="command">the command to send</param> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns>The command result</returns> | ||
Task<TCommandResult> SendAsync<TCommandResult>(ICommand<TCommandResult> command, CancellationToken cancellationToken = default); | ||
/// <typeparam name="TCommandResult">The type of the result returned by the command.</typeparam> | ||
/// <param name="command">The command to be sent.</param> | ||
/// <param name="commandMediationSettings">Optional settings for command mediation.</param> | ||
/// <param name="cancellationToken">Cancellation token for the operation.</param> | ||
/// <returns>A task representing the asynchronous operation with a result of type <typeparamref name="TCommandResult"/>.</returns> | ||
Task<TCommandResult> SendAsync<TCommandResult>(ICommand<TCommandResult> command, | ||
CommandMediationSettings? commandMediationSettings = null, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
using System.Threading; | ||
#nullable enable | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace LiteBus.Events.Abstractions; | ||
|
||
/// <summary> | ||
/// Defines the interface for an event mediator that facilitates the publishing of events. | ||
/// Represents the mediator interface for publishing events within the application. | ||
/// </summary> | ||
public interface IEventMediator | ||
{ | ||
/// <summary> | ||
/// Publishes an event asynchronously. | ||
/// Asynchronously publishes an event. | ||
/// </summary> | ||
/// <param name="event">The event to publish.</param> | ||
/// <param name="settings">Optional settings for event mediation. If null, default settings are used.</param> | ||
/// <param name="cancellationToken">A token for cancelling the publish operation.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
Task PublishAsync(IEvent @event, EventMediationSettings settings = null, CancellationToken cancellationToken = default); | ||
/// <param name="event">The event to be published.</param> | ||
/// <param name="eventMediationSettings">Optional settings for event mediation.</param> | ||
/// <param name="cancellationToken">Cancellation token for the operation.</param> | ||
/// <returns>A task representing the asynchronous event publication operation.</returns> | ||
Task PublishAsync(IEvent @event, EventMediationSettings? eventMediationSettings = null, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Publishes an event asynchronously. | ||
/// Asynchronously publishes an event with a specific type. | ||
/// </summary> | ||
/// <typeparam name="TEvent">The type of the event to publish.</typeparam> | ||
/// <param name="event">The event to publish.</param> | ||
/// <param name="settings">Optional settings for event mediation. If null, default settings are used.</param> | ||
/// <param name="cancellationToken">A token for cancelling the publish operation.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
Task PublishAsync<TEvent>(TEvent @event, EventMediationSettings settings = null, CancellationToken cancellationToken = default); | ||
/// <typeparam name="TEvent">The type of the event to be published.</typeparam> | ||
/// <param name="event">The event to be published.</param> | ||
/// <param name="eventMediationSettings">Optional settings for event mediation.</param> | ||
/// <param name="cancellationToken">Cancellation token for the operation.</param> | ||
/// <returns>A task representing the asynchronous event publication operation.</returns> | ||
Task PublishAsync<TEvent>(TEvent @event, EventMediationSettings? eventMediationSettings = null, CancellationToken cancellationToken = default) where TEvent : notnull; | ||
} |
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.