Skip to content

Commit

Permalink
Added XMl comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiseni committed Oct 18, 2024
1 parent 06c39fe commit 309aba9
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<GenerateDocumentationFile>false</GenerateDocumentationFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Deterministic>true</Deterministic>
</PropertyGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/Pozitron.Extensions.MediatR/ExtendedMediator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

namespace MediatR;

/// <summary>
/// Extended mediator implementation.
/// </summary>
/// <param name="serviceScopeFactory"></param>
/// <param name="serviceProvider"></param>
public class ExtendedMediator(
IServiceScopeFactory serviceScopeFactory,
IServiceProvider serviceProvider)
Expand All @@ -18,6 +23,14 @@ public class ExtendedMediator(
[(int)PublishStrategy.WhenAll] = new WhenAllPublisher(),
};

/// <summary>
/// Asynchronously send a notification to multiple handlers using the specified strategy.
/// </summary>
/// <typeparam name="TNotification"></typeparam>
/// <param name="notification">Notification object</param>
/// <param name="strategy">Publish strategy</param>
/// <param name="cancellationToken">Optional cancellation token</param>
/// <returns>A task that represents the publish operation.</returns>
public Task Publish<TNotification>(
TNotification notification,
PublishStrategy strategy,
Expand Down
66 changes: 62 additions & 4 deletions src/Pozitron.Extensions.MediatR/MediatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@

namespace MediatR;

/// <summary>
/// ExtendedMediator extensions.
/// DI extensions to scan for MediatR handlers and registers them.
/// </summary>
public static class MediatorExtensions
{
/// <summary>
/// Asynchronously send a notification to multiple handlers using the specified strategy.
/// </summary>
/// <typeparam name="TNotification"></typeparam>
/// <param name="publisher"></param>
/// <param name="notification">Notification object</param>
/// <param name="strategy">Publish strategy</param>
/// <param name="cancellationToken">Optional cancellation token</param>
/// <returns>A task that represents the publish operation.</returns>
/// <exception cref="NotSupportedException">Throws if the MediatorImplementationType is not configured to ExtendedMediator</exception>
public static Task Publish<TNotification>(
this IPublisher publisher,
TNotification notification,
Expand All @@ -17,23 +31,46 @@ public static Task Publish<TNotification>(
: throw new NotSupportedException("The extended mediator implementation is not registered! Register it with the IServiceCollection.AddExtendedMediatR extensions.");
}

/// <summary>
/// Registers handlers and mediator types.
/// The MediatorImplementationType is always set to ExtendedMediator.
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="lifetime">Service lifetime to register services under</param>
/// <param name="types">Types from assemblies to scan</param>
/// <returns>Service collection</returns>
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);
}

/// <summary>
/// Registers handlers and mediator types.
/// The MediatorImplementationType is always set to ExtendedMediator.
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="types">Types from assemblies to scan</param>
/// <returns>Service collection</returns>
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);
}

/// <summary>
/// Registers handlers and mediator types.
/// The MediatorImplementationType is always set to ExtendedMediator.
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="lifetime">Service lifetime to register services under</param>
/// <param name="assemblies">Assemblies to scan</param>
/// <returns>Service collection</returns>
public static IServiceCollection AddExtendedMediatR(
this IServiceCollection services,
ServiceLifetime lifetime,
Expand All @@ -46,6 +83,13 @@ public static IServiceCollection AddExtendedMediatR(
return services.AddExtendedMediatR(serviceConfig);
}

/// <summary>
/// Registers handlers and mediator types.
/// The MediatorImplementationType is always set to ExtendedMediator.
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="assemblies">Assemblies to scan</param>
/// <returns>Service collection</returns>
public static IServiceCollection AddExtendedMediatR(
this IServiceCollection services,
params Assembly[] assemblies)
Expand All @@ -56,6 +100,13 @@ public static IServiceCollection AddExtendedMediatR(
return services.AddExtendedMediatR(serviceConfig);
}

/// <summary>
/// Registers handlers and mediator types from the specified assemblies
/// The MediatorImplementationType is always set to ExtendedMediator.
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configuration">The action used to configure the options</param>
/// <returns>Service collection</returns>
public static IServiceCollection AddExtendedMediatR(
this IServiceCollection services,
Action<MediatRServiceConfiguration> configuration)
Expand All @@ -66,6 +117,13 @@ public static IServiceCollection AddExtendedMediatR(
return services.AddExtendedMediatR(serviceConfig);
}

/// <summary>
/// Registers handlers and mediator types from the specified assemblies.
/// The MediatorImplementationType is always set to ExtendedMediator.
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configuration">Configuration options</param>
/// <returns>Service collection</returns>
public static IServiceCollection AddExtendedMediatR(
this IServiceCollection services,
MediatRServiceConfiguration configuration)
Expand Down
39 changes: 21 additions & 18 deletions src/Pozitron.Extensions.MediatR/PublishStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace MediatR;

/// <summary>
/// The strategy to use when publishing a notification.
/// </summary>
public enum PublishStrategy
{
/// <summary>
Expand All @@ -8,44 +11,44 @@ public enum PublishStrategy
Default = 0,

/// <summary>
/// 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.<br/>
/// Returns when all handlers complete or an exception has been thrown.<br/>
/// In case of an exception, the rest of the handlers are not executed.<br/>
/// </summary>
Sequential = 1,

/// <summary>
/// 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.<br/>
/// Returns when all handlers complete. It continues on exception(s).<br/>
/// In case of any exception(s), they will be captured in an AggregateException.<br/>
/// </summary>
SequentialAll = 2,

/// <summary>
/// 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.<br/>
/// In case of any exception(s), they will be flattened and captured in an AggregateException.<br/>
/// The AggregateException will contain all exceptions thrown by all handlers, including OperationCanceled exceptions.<br/>
/// </summary>
WhenAll = 3,

/// <summary>
/// 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).
/// Creates a single new thread using Task.Run(), and returns Task.Completed immediately.<br/>
/// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers sequentially.<br/>
/// In case of an exception, it stops further execution. The exception is logged using ILogger&lt;T&gt; (if it's registered in DI).<br/>
/// </summary>
SequentialBackground = 11,

/// <summary>
/// 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).
/// Creates a single new thread using Task.Run(), and returns Task.Completed immediately.<br/>
/// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers sequentially.<br/>
/// In case of exceptions, they are logged using ILogger&lt;T&gt; (if it's registered in DI).<br/>
/// </summary>
SequentialAllBackground = 12,

/// <summary>
/// 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).
/// Creates a single new thread using Task.Run(), and returns Task.Completed immediately.<br/>
/// Creates a new scope using IServiceScopeFactory, executes and awaits all handlers using Task.WhenAll.<br/>
/// In case of exceptions, they are logged using ILogger&lt;T&gt; (if it's registered in DI).<br/>
/// </summary>
WhenAllBackground = 13
}

0 comments on commit 309aba9

Please sign in to comment.