-
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.
Add
QueryMediatorExtensions
, CommandMediatorExtensions
, and `Even…
…tMediatorExtensions` for backward compatibility
- Loading branch information
Showing
58 changed files
with
302 additions
and
105 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
112 changes: 112 additions & 0 deletions
112
src/LiteBus.Commands.Abstractions/Extensions/CommandMediatorExtensions.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,112 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace LiteBus.Commands.Abstractions; | ||
|
||
/// <summary> | ||
/// Provides extension methods for <see cref="ICommandMediator"/> to simplify command sending operations. | ||
/// </summary> | ||
public static class CommandMediatorExtensions | ||
{ | ||
/// <summary> | ||
/// Sends a command asynchronously using the specified command mediator. | ||
/// </summary> | ||
/// <param name="commandMediator">The command mediator to use for sending the command.</param> | ||
/// <param name="command">The command to send.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the send operation.</param> | ||
/// <returns>A task representing the asynchronous send operation.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// await commandMediator.SendAsync(myCommand, cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task SendAsync(this ICommandMediator commandMediator, | ||
ICommand command, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return commandMediator.SendAsync(command, null, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Sends a command asynchronously using the specified command mediator and returns a result. | ||
/// </summary> | ||
/// <typeparam name="TCommandResult">The type of the result returned by the command.</typeparam> | ||
/// <param name="commandMediator">The command mediator to use for sending the command.</param> | ||
/// <param name="command">The command to send.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the send operation.</param> | ||
/// <returns>A task representing the asynchronous operation, containing the result of the command.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// var result = await commandMediator.SendAsync(myCommand, cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task<TCommandResult> SendAsync<TCommandResult>(this ICommandMediator commandMediator, | ||
ICommand<TCommandResult> command, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return commandMediator.SendAsync(command, null, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Sends a tagged command asynchronously using the specified command mediator. | ||
/// </summary> | ||
/// <param name="commandMediator">The command mediator to use for sending the command.</param> | ||
/// <param name="command">The command to send.</param> | ||
/// <param name="tag">A tag that specifies the context or category of the command.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the send operation.</param> | ||
/// <returns>A task representing the asynchronous send operation.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// await commandMediator.SendAsync(myCommand, "UserAction", cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task SendAsync(this ICommandMediator commandMediator, | ||
ICommand command, | ||
string tag, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return commandMediator.SendAsync(command, | ||
new CommandMediationSettings | ||
{ | ||
Filters = | ||
{ | ||
Tags = new[] { tag } | ||
} | ||
}, | ||
cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Sends a tagged command asynchronously using the specified command mediator and returns a result. | ||
/// </summary> | ||
/// <typeparam name="TCommandResult">The type of the result returned by the command.</typeparam> | ||
/// <param name="commandMediator">The command mediator to use for sending the command.</param> | ||
/// <param name="command">The command to send.</param> | ||
/// <param name="tag">A tag that specifies the context or category of the command.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the send operation.</param> | ||
/// <returns>A task representing the asynchronous operation, containing the result of the command.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// var result = await commandMediator.SendAsync(myCommand, "UserAction", cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task<TCommandResult> SendAsync<TCommandResult>(this ICommandMediator commandMediator, | ||
ICommand<TCommandResult> command, | ||
string tag, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return commandMediator.SendAsync(command, | ||
new CommandMediationSettings | ||
{ | ||
Filters = | ||
{ | ||
Tags = new[] { tag } | ||
} | ||
}, | ||
cancellationToken); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/LiteBus.Commands.Abstractions/LiteBus.Commands.Abstractions.csproj.DotSettings
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,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
55 changes: 55 additions & 0 deletions
55
src/LiteBus.Events.Abstractions/Extensions/EventMediatorExtensions.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,55 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace LiteBus.Events.Abstractions; | ||
|
||
/// <summary> | ||
/// Provides extension methods for <see cref="IEventMediator"/> for simplified event publishing. | ||
/// </summary> | ||
public static class EventMediatorExtensions | ||
{ | ||
/// <summary> | ||
/// Publishes an event asynchronously using the specified event mediator. | ||
/// </summary> | ||
/// <param name="eventMediator">The event mediator to use for publishing the event.</param> | ||
/// <param name="event">The event to publish.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the publish operation.</param> | ||
/// <returns>A task that represents the asynchronous publish operation.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// await eventMediator.PublishAsync(myEvent, cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task PublishAsync(this IEventMediator eventMediator, IEvent @event, CancellationToken cancellationToken = default) | ||
{ | ||
return eventMediator.PublishAsync(@event, null, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Publishes an event asynchronously using the specified event mediator with a specific tag. | ||
/// </summary> | ||
/// <param name="eventMediator">The event mediator to use for publishing the event.</param> | ||
/// <param name="event">The event to publish.</param> | ||
/// <param name="tag">A tag that specifies the context or category of the event.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the publish operation.</param> | ||
/// <returns>A task that represents the asynchronous publish operation.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// await eventMediator.PublishAsync(myEvent, "UserAction", cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task PublishAsync(this IEventMediator eventMediator, IEvent @event, string tag, CancellationToken cancellationToken = default) | ||
{ | ||
return eventMediator.PublishAsync(@event, | ||
new EventMediationSettings | ||
{ | ||
Filters = | ||
{ | ||
Tags = new[] { tag } | ||
} | ||
}, | ||
cancellationToken); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
src/LiteBus.Events.Abstractions/LiteBus.Events.Abstractions.csproj.DotSettings
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,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
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
1 change: 0 additions & 1 deletion
1
src/LiteBus.Messaging.Abstractions/Extensions/MessageContextExtensions.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,4 +1,3 @@ | ||
using System; | ||
using System.Runtime.ExceptionServices; | ||
using System.Threading.Tasks; | ||
|
||
|
121 changes: 121 additions & 0 deletions
121
src/LiteBus.Queries.Abstractions/Extensions/QueryMediatorExtensions.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,121 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace LiteBus.Queries.Abstractions; | ||
|
||
/// <summary> | ||
/// Provides extension methods for <see cref="IQueryMediator"/> to simplify querying and streaming operations. | ||
/// </summary> | ||
public static class QueryMediatorExtensions | ||
{ | ||
/// <summary> | ||
/// Executes a query asynchronously using the specified query mediator. | ||
/// </summary> | ||
/// <typeparam name="TQueryResult">The type of the result returned by the query.</typeparam> | ||
/// <param name="queryMediator">The query mediator to use for executing the query.</param> | ||
/// <param name="query">The query to execute.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the query operation.</param> | ||
/// <returns>A task representing the asynchronous operation, containing the result of the query.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// var result = await queryMediator.QueryAsync(myQuery, cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task<TQueryResult> QueryAsync<TQueryResult>(this IQueryMediator queryMediator, | ||
IQuery<TQueryResult> query, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return queryMediator.QueryAsync(@query, null, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Streams query results asynchronously using the specified query mediator. | ||
/// </summary> | ||
/// <typeparam name="TQueryResult">The type of the results returned by the stream query.</typeparam> | ||
/// <param name="queryMediator">The query mediator to use for executing the stream query.</param> | ||
/// <param name="query">The stream query to execute.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the stream operation.</param> | ||
/// <returns>An async enumerable representing the stream of results.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// await foreach (var item in queryMediator.StreamAsync(myStreamQuery, cancellationToken)) | ||
/// { | ||
/// // Process each item | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static IAsyncEnumerable<TQueryResult> StreamAsync<TQueryResult>(this IQueryMediator queryMediator, | ||
IStreamQuery<TQueryResult> query, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return queryMediator.StreamAsync(query, null, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Executes a tagged query asynchronously using the specified query mediator. | ||
/// </summary> | ||
/// <typeparam name="TQueryResult">The type of the result returned by the query.</typeparam> | ||
/// <param name="queryMediator">The query mediator to use for executing the query.</param> | ||
/// <param name="query">The query to execute.</param> | ||
/// <param name="tag">A tag that specifies the context or category of the query.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the query operation.</param> | ||
/// <returns>A task representing the asynchronous operation, containing the result of the query.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// var result = await queryMediator.QueryAsync(myQuery, "UserQuery", cancellationToken); | ||
/// </code> | ||
/// </example> | ||
public static Task<TQueryResult> QueryAsync<TQueryResult>(this IQueryMediator queryMediator, | ||
IQuery<TQueryResult> query, | ||
string tag, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return queryMediator.QueryAsync(@query, | ||
new QueryMediationSettings | ||
{ | ||
Filters = | ||
{ | ||
Tags = new[] { tag } | ||
} | ||
}, | ||
cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Streams tagged query results asynchronously using the specified query mediator. | ||
/// </summary> | ||
/// <typeparam name="TQueryResult">The type of the results returned by the stream query.</typeparam> | ||
/// <param name="queryMediator">The query mediator to use for executing the stream query.</param> | ||
/// <param name="query">The stream query to execute.</param> | ||
/// <param name="tag">A tag that specifies the context or category of the query.</param> | ||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the stream operation.</param> | ||
/// <returns>An async enumerable representing the stream of results.</returns> | ||
/// <example> | ||
/// Usage example: | ||
/// <code> | ||
/// await foreach (var item in queryMediator.StreamAsync(myStreamQuery, "UserQueryStream", cancellationToken)) | ||
/// { | ||
/// // Process each item | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static IAsyncEnumerable<TQueryResult> StreamAsync<TQueryResult>(this IQueryMediator queryMediator, | ||
IStreamQuery<TQueryResult> query, | ||
string tag, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return queryMediator.StreamAsync(query, | ||
new QueryMediationSettings | ||
{ | ||
Filters = | ||
{ | ||
Tags = new[] { tag } | ||
} | ||
}, | ||
cancellationToken); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/LiteBus.Queries.Abstractions/LiteBus.Queries.Abstractions.csproj.DotSettings
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,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
1 change: 0 additions & 1 deletion
1
tests/LiteBus.Commands.UnitTests/UseCases/CommandWithTag/CommandWithTagPreHandler3.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
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeCommand/Handlers/FakeCommandHandlerWithoutResult.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
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeCommand/Messages/FakeCommandResult.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,5 +1,3 @@ | ||
using System; | ||
|
||
namespace LiteBus.UnitTests.Data.FakeCommand.Messages; | ||
|
||
public sealed class FakeCommandResult | ||
|
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeCommand/PostHandlers/FakeCommandPostHandler.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
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeCommand/PreHandlers/FakeCommandPreHandler.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
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeEvent/Handlers/FakeEventHandler1.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
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeEvent/Handlers/FakeEventHandler2.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
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeEvent/Handlers/FakeEventHandler3.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
2 changes: 0 additions & 2 deletions
2
tests/LiteBus.UnitTests/Data/FakeEvent/PostHandlers/FakeEventPostHandler.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
Oops, something went wrong.