Skip to content

Commit 5a0cf76

Browse files
authored
Merge pull request #22 from KuraiAndras/remove-unused-exceptions
Remove unused exceptions, add comments
2 parents 0e4073b + a87afa2 commit 5a0cf76

File tree

5 files changed

+72
-52
lines changed

5 files changed

+72
-52
lines changed

MediatR.Courier/CourierInjector.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@
44

55
namespace MediatR.Courier;
66

7+
/// <summary>
8+
/// Provides extension methods for registering MediatR Courier services with the dependency injection container.
9+
/// </summary>
710
public static class CourierInjector
811
{
12+
/// <summary>
13+
/// Registers MediatR Courier services with the dependency injection container using default configuration.
14+
/// </summary>
15+
/// <param name="services">The service collection to add services to.</param>
16+
/// <param name="assemblies">The assemblies to scan for notification types.</param>
17+
/// <returns>The service collection for chaining.</returns>
918
public static IServiceCollection AddCourier(this IServiceCollection services, params Assembly[] assemblies) =>
1019
services.AddCourier(_ => { }, assemblies);
1120

21+
/// <summary>
22+
/// Registers MediatR Courier services with the dependency injection container using custom configuration.
23+
/// </summary>
24+
/// <param name="services">The service collection to add services to.</param>
25+
/// <param name="configure">An action to configure the courier options.</param>
26+
/// <param name="assemblies">The assemblies to scan for notification types.</param>
27+
/// <returns>The service collection for chaining.</returns>
1228
public static IServiceCollection AddCourier(this IServiceCollection services, Action<CourierOptions> configure, params Assembly[] assemblies)
1329
{
1430
var options = new CourierOptions();

MediatR.Courier/CourierOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
namespace MediatR.Courier;
22

3+
/// <summary>
4+
/// Configuration options for MediatR Courier behavior.
5+
/// </summary>
36
public sealed class CourierOptions
47
{
8+
/// <summary>
9+
/// Gets or sets a value indicating whether to capture the thread context when awaiting tasks.
10+
/// This is used like: ConfigureAwait(CaptureThreadContext).
11+
/// Defaults to false.
12+
/// </summary>
513
public bool CaptureThreadContext { get; set; }
614
}

MediatR.Courier/Exceptions/MethodNotImplementedException.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

MediatR.Courier/Exceptions/UnknownMethodException.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

MediatR.Courier/ICourier.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,88 @@
11
namespace MediatR.Courier;
22

3+
/// <summary>
4+
/// Provides functionality for subscribing to and unsubscribing from MediatR notifications
5+
/// with support for both strong and weak reference handlers.
6+
/// </summary>
37
public interface ICourier
48
{
9+
/// <summary>
10+
/// Subscribes a handler to receive notifications of the specified type.
11+
/// The handler will be held with a strong reference.
12+
/// </summary>
13+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
14+
/// <param name="handler">The handler to invoke when a notification is published.</param>
515
void Subscribe<TNotification>(Action<TNotification> handler)
616
where TNotification : INotification;
717

18+
/// <inheritdoc cref="Subscribe{TNotification}(Action{TNotification})"/>
19+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
20+
/// <param name="handler">The handler to invoke when a notification is published.</param>
821
void Subscribe<TNotification>(Action<TNotification, CancellationToken> handler)
922
where TNotification : INotification;
1023

24+
/// <inheritdoc cref="Subscribe{TNotification}(Action{TNotification})"/>
25+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
26+
/// <param name="handler">The handler to invoke when a notification is published.</param>
1127
void Subscribe<TNotification>(Func<TNotification, Task> handler)
1228
where TNotification : INotification;
1329

30+
/// <inheritdoc cref="Subscribe{TNotification}(Action{TNotification})"/>
31+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
32+
/// <param name="handler">The handler to invoke when a notification is published.</param>
1433
void Subscribe<TNotification>(Func<TNotification, CancellationToken, Task> handler)
1534
where TNotification : INotification;
1635

36+
/// <summary>
37+
/// Subscribes a handler to receive notifications of the specified type using a weak reference.
38+
/// The handler will be held with a weak reference, allowing the target object to be garbage collected.
39+
/// </summary>
40+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
41+
/// <param name="handler">The handler to invoke when a notification is published.</param>
1742
void SubscribeWeak<TNotification>(Action<TNotification> handler)
1843
where TNotification : INotification;
1944

45+
/// <inheritdoc cref="SubscribeWeak{TNotification}(Action{TNotification})"/>
46+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
47+
/// <param name="handler">The handler to invoke when a notification is published.</param>
2048
void SubscribeWeak<TNotification>(Action<TNotification, CancellationToken> handler)
2149
where TNotification : INotification;
2250

51+
/// <inheritdoc cref="SubscribeWeak{TNotification}(Action{TNotification})"/>
52+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
53+
/// <param name="handler">The handler to invoke when a notification is published.</param>
2354
void SubscribeWeak<TNotification>(Func<TNotification, Task> handler)
2455
where TNotification : INotification;
2556

57+
/// <inheritdoc cref="SubscribeWeak{TNotification}(Action{TNotification})"/>
58+
/// <typeparam name="TNotification">The type of notification to subscribe to.</typeparam>
59+
/// <param name="handler">The handler to invoke when a notification is published.</param>
2660
void SubscribeWeak<TNotification>(Func<TNotification, CancellationToken, Task> handler)
2761
where TNotification : INotification;
2862

63+
/// <summary>
64+
/// Unsubscribes a handler from receiving notifications of the specified type.
65+
/// </summary>
66+
/// <typeparam name="TNotification">The type of notification to unsubscribe from.</typeparam>
67+
/// <param name="handler">The handler to remove from the subscription list.</param>
2968
void UnSubscribe<TNotification>(Action<TNotification> handler)
3069
where TNotification : INotification;
3170

71+
/// <inheritdoc cref="UnSubscribe{TNotification}(Action{TNotification})"/>
72+
/// <typeparam name="TNotification">The type of notification to unsubscribe from.</typeparam>
73+
/// <param name="handler">The handler to remove from the subscription list.</param>
3274
void UnSubscribe<TNotification>(Action<TNotification, CancellationToken> handler)
3375
where TNotification : INotification;
3476

77+
/// <inheritdoc cref="UnSubscribe{TNotification}(Action{TNotification})"/>
78+
/// <typeparam name="TNotification">The type of notification to unsubscribe from.</typeparam>
79+
/// <param name="handler">The handler to remove from the subscription list.</param>
3580
void UnSubscribe<TNotification>(Func<TNotification, Task> handler)
3681
where TNotification : INotification;
3782

83+
/// <inheritdoc cref="UnSubscribe{TNotification}(Action{TNotification})"/>
84+
/// <typeparam name="TNotification">The type of notification to unsubscribe from.</typeparam>
85+
/// <param name="handler">The handler to remove from the subscription list.</param>
3886
void UnSubscribe<TNotification>(Func<TNotification, CancellationToken, Task> handler)
3987
where TNotification : INotification;
4088
}

0 commit comments

Comments
 (0)