From 309aba94ebb81bcd7234fd282f722e8d6912a111 Mon Sep 17 00:00:00 2001 From: Fati Iseni Date: Fri, 18 Oct 2024 12:57:34 +0200 Subject: [PATCH] Added XMl comments. --- src/Directory.Build.props | 2 +- .../ExtendedMediator.cs | 13 ++++ .../MediatorExtensions.cs | 66 +++++++++++++++++-- .../PublishStrategy.cs | 39 ++++++----- 4 files changed, 97 insertions(+), 23 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 54f904f..4999a6b 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -7,7 +7,7 @@ enable latest - false + true false true diff --git a/src/Pozitron.Extensions.MediatR/ExtendedMediator.cs b/src/Pozitron.Extensions.MediatR/ExtendedMediator.cs index 98e6502..0bf7da5 100644 --- a/src/Pozitron.Extensions.MediatR/ExtendedMediator.cs +++ b/src/Pozitron.Extensions.MediatR/ExtendedMediator.cs @@ -3,6 +3,11 @@ namespace MediatR; +/// +/// Extended mediator implementation. +/// +/// +/// public class ExtendedMediator( IServiceScopeFactory serviceScopeFactory, IServiceProvider serviceProvider) @@ -18,6 +23,14 @@ public class ExtendedMediator( [(int)PublishStrategy.WhenAll] = new WhenAllPublisher(), }; + /// + /// Asynchronously send a notification to multiple handlers using the specified strategy. + /// + /// + /// Notification object + /// Publish strategy + /// Optional cancellation token + /// A task that represents the publish operation. public Task Publish( TNotification notification, PublishStrategy strategy, diff --git a/src/Pozitron.Extensions.MediatR/MediatorExtensions.cs b/src/Pozitron.Extensions.MediatR/MediatorExtensions.cs index 226511e..e200442 100644 --- a/src/Pozitron.Extensions.MediatR/MediatorExtensions.cs +++ b/src/Pozitron.Extensions.MediatR/MediatorExtensions.cs @@ -3,8 +3,22 @@ namespace MediatR; +/// +/// ExtendedMediator extensions. +/// DI extensions to scan for MediatR handlers and registers them. +/// public static class MediatorExtensions { + /// + /// Asynchronously send a notification to multiple handlers using the specified strategy. + /// + /// + /// + /// Notification object + /// Publish strategy + /// Optional cancellation token + /// A task that represents the publish operation. + /// Throws if the MediatorImplementationType is not configured to ExtendedMediator public static Task Publish( this IPublisher publisher, TNotification notification, @@ -17,23 +31,46 @@ public static Task Publish( : throw new NotSupportedException("The extended mediator implementation is not registered! Register it with the IServiceCollection.AddExtendedMediatR extensions."); } + /// + /// Registers handlers and mediator types. + /// The MediatorImplementationType is always set to ExtendedMediator. + /// + /// Service collection + /// Service lifetime to register services under + /// Types from assemblies to scan + /// Service collection public static IServiceCollection AddExtendedMediatR( this IServiceCollection services, ServiceLifetime lifetime, - params Type[] handlerAssemblyMarkerTypes) + params Type[] types) { - var assemblies = handlerAssemblyMarkerTypes.Select(x => x.Assembly).ToArray(); + var assemblies = types.Select(x => x.Assembly).ToArray(); return services.AddExtendedMediatR(lifetime, assemblies); } + /// + /// Registers handlers and mediator types. + /// The MediatorImplementationType is always set to ExtendedMediator. + /// + /// Service collection + /// Types from assemblies to scan + /// Service collection public static IServiceCollection AddExtendedMediatR( this IServiceCollection services, - params Type[] handlerAssemblyMarkerTypes) + params Type[] types) { - var assemblies = handlerAssemblyMarkerTypes.Select(x => x.Assembly).ToArray(); + var assemblies = types.Select(x => x.Assembly).ToArray(); return services.AddExtendedMediatR(assemblies); } + /// + /// Registers handlers and mediator types. + /// The MediatorImplementationType is always set to ExtendedMediator. + /// + /// Service collection + /// Service lifetime to register services under + /// Assemblies to scan + /// Service collection public static IServiceCollection AddExtendedMediatR( this IServiceCollection services, ServiceLifetime lifetime, @@ -46,6 +83,13 @@ public static IServiceCollection AddExtendedMediatR( return services.AddExtendedMediatR(serviceConfig); } + /// + /// Registers handlers and mediator types. + /// The MediatorImplementationType is always set to ExtendedMediator. + /// + /// Service collection + /// Assemblies to scan + /// Service collection public static IServiceCollection AddExtendedMediatR( this IServiceCollection services, params Assembly[] assemblies) @@ -56,6 +100,13 @@ public static IServiceCollection AddExtendedMediatR( return services.AddExtendedMediatR(serviceConfig); } + /// + /// Registers handlers and mediator types from the specified assemblies + /// The MediatorImplementationType is always set to ExtendedMediator. + /// + /// Service collection + /// The action used to configure the options + /// Service collection public static IServiceCollection AddExtendedMediatR( this IServiceCollection services, Action configuration) @@ -66,6 +117,13 @@ public static IServiceCollection AddExtendedMediatR( return services.AddExtendedMediatR(serviceConfig); } + /// + /// Registers handlers and mediator types from the specified assemblies. + /// The MediatorImplementationType is always set to ExtendedMediator. + /// + /// Service collection + /// Configuration options + /// Service collection public static IServiceCollection AddExtendedMediatR( this IServiceCollection services, MediatRServiceConfiguration configuration) diff --git a/src/Pozitron.Extensions.MediatR/PublishStrategy.cs b/src/Pozitron.Extensions.MediatR/PublishStrategy.cs index 90f2fff..cfb4020 100644 --- a/src/Pozitron.Extensions.MediatR/PublishStrategy.cs +++ b/src/Pozitron.Extensions.MediatR/PublishStrategy.cs @@ -1,5 +1,8 @@ namespace MediatR; +/// +/// The strategy to use when publishing a notification. +/// public enum PublishStrategy { /// @@ -8,44 +11,44 @@ public enum PublishStrategy Default = 0, /// - /// Executes and awaits each notification handler one after another. - /// Returns when all handlers complete or an exception has been thrown. - /// In case of an exception, the rest of the handlers are not executed. + /// Executes and awaits each notification handler one after another.
+ /// Returns when all handlers complete or an exception has been thrown.
+ /// In case of an exception, the rest of the handlers are not executed.
///
Sequential = 1, /// - /// Executes and awaits each notification handler one after another. - /// Returns when all handlers complete. It continues on exception(s). - /// In case of any exception(s), they will be captured in an AggregateException. + /// Executes and awaits each notification handler one after another.
+ /// Returns when all handlers complete. It continues on exception(s).
+ /// In case of any exception(s), they will be captured in an AggregateException.
///
SequentialAll = 2, /// - /// Executes and awaits all notification handlers using Task.WhenAll. It does not create a separate thread explicitly. - /// In case of any exception(s), they will be flattened and captured in an AggregateException. - /// The AggregateException will contain all exceptions thrown by all handlers, including OperationCanceled exceptions. + /// Executes and awaits all notification handlers using Task.WhenAll. It does not create a separate thread explicitly.
+ /// In case of any exception(s), they will be flattened and captured in an AggregateException.
+ /// The AggregateException will contain all exceptions thrown by all handlers, including OperationCanceled exceptions.
///
WhenAll = 3, /// - /// Creates a single new thread using Task.Run(), and returns Task.Completed immediately. - /// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers sequentially. - /// In case of an exception, it stops further execution. The exception is logged using ILogger (if it's registered in DI). + /// Creates a single new thread using Task.Run(), and returns Task.Completed immediately.
+ /// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers sequentially.
+ /// In case of an exception, it stops further execution. The exception is logged using ILogger<T> (if it's registered in DI).
///
SequentialBackground = 11, /// - /// Creates a single new thread using Task.Run(), and returns Task.Completed immediately. - /// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers sequentially. - /// In case of exceptions, they are logged using ILogger (if it's registered in DI). + /// Creates a single new thread using Task.Run(), and returns Task.Completed immediately.
+ /// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers sequentially.
+ /// In case of exceptions, they are logged using ILogger<T> (if it's registered in DI).
///
SequentialAllBackground = 12, /// - /// Creates a single new thread using Task.Run(), and returns Task.Completed immediately. - /// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers using Task.WhenAll. - /// In case of exceptions, they are logged using ILogger (if it's registered in DI). + /// Creates a single new thread using Task.Run(), and returns Task.Completed immediately.
+ /// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers using Task.WhenAll.
+ /// In case of exceptions, they are logged using ILogger<T> (if it's registered in DI).
///
WhenAllBackground = 13 }