Skip to content

Commit d4a23d5

Browse files
authored
refactor: Move IMediator interface to abstractions package (#45)
1 parent 258c99f commit d4a23d5

3 files changed

Lines changed: 46 additions & 27 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using DispatchR.Abstractions.Notification;
2+
using DispatchR.Abstractions.Send;
3+
using DispatchR.Abstractions.Stream;
4+
5+
namespace DispatchR;
6+
7+
public interface IMediator
8+
{
9+
TResponse Send<TRequest, TResponse>(IRequest<TRequest, TResponse> request,
10+
CancellationToken cancellationToken) where TRequest : class, IRequest;
11+
12+
IAsyncEnumerable<TResponse> CreateStream<TRequest, TResponse>(IStreamRequest<TRequest, TResponse> request,
13+
CancellationToken cancellationToken) where TRequest : class, IStreamRequest;
14+
15+
ValueTask Publish<TNotification>(TNotification request, CancellationToken cancellationToken)
16+
where TNotification : INotification;
17+
18+
/// <summary>
19+
/// This method is not recommended for performance-critical scenarios.
20+
/// Use it only if it is strictly necessary, as its performance is lower compared
21+
/// to similar methods in terms of both memory usage and CPU consumption.
22+
/// </summary>
23+
/// <param name="request">
24+
/// An object that implements INotification
25+
/// </param>
26+
/// <param name="cancellationToken"></param>
27+
/// <returns></returns>
28+
[Obsolete(message: "This method has performance issues. Use only if strictly necessary", error: false)]
29+
ValueTask Publish(object request, CancellationToken cancellationToken);
30+
}
Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,6 @@
77

88
namespace DispatchR;
99

10-
public interface IMediator
11-
{
12-
TResponse Send<TRequest, TResponse>(IRequest<TRequest, TResponse> request,
13-
CancellationToken cancellationToken) where TRequest : class, IRequest;
14-
15-
IAsyncEnumerable<TResponse> CreateStream<TRequest, TResponse>(IStreamRequest<TRequest, TResponse> request,
16-
CancellationToken cancellationToken) where TRequest : class, IStreamRequest;
17-
18-
ValueTask Publish<TNotification>(TNotification request, CancellationToken cancellationToken)
19-
where TNotification : INotification;
20-
21-
/// <summary>
22-
/// This method is not recommended for performance-critical scenarios.
23-
/// Use it only if it is strictly necessary, as its performance is lower compared
24-
/// to similar methods in terms of both memory usage and CPU consumption.
25-
/// </summary>
26-
/// <param name="request">
27-
/// An object that implements INotification
28-
/// </param>
29-
/// <param name="cancellationToken"></param>
30-
/// <returns></returns>
31-
[Obsolete(message: "This method has performance issues. Use only if strictly necessary",
32-
error: false,
33-
DiagnosticId = Constants.DiagnosticPerformanceIssue)]
34-
ValueTask Publish(object request, CancellationToken cancellationToken);
35-
}
36-
3710
public sealed class Mediator(IServiceProvider serviceProvider) : IMediator
3811
{
3912
public TResponse Send<TRequest, TResponse>(IRequest<TRequest, TResponse> request,
@@ -73,6 +46,19 @@ public async ValueTask Publish<TNotification>(TNotification request, Cancellatio
7346
}
7447
}
7548

49+
/// <summary>
50+
/// This method is not recommended for performance-critical scenarios.
51+
/// Use it only if it is strictly necessary, as its performance is lower compared
52+
/// to similar methods in terms of both memory usage and CPU consumption.
53+
/// </summary>
54+
/// <param name="request">
55+
/// An object that implements INotification
56+
/// </param>
57+
/// <param name="cancellationToken"></param>
58+
/// <returns></returns>
59+
[Obsolete(message: "This method has performance issues. Use only if strictly necessary",
60+
error: false,
61+
DiagnosticId = Constants.DiagnosticPerformanceIssue)]
7662
public async ValueTask Publish(object request, CancellationToken cancellationToken)
7763
{
7864
ArgumentNullException.ThrowIfNull(request);

src/DispatchR/TypeForwarders.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly:TypeForwardedTo(typeof(DispatchR.IMediator))]

0 commit comments

Comments
 (0)