Skip to content

Commit

Permalink
CancellableToken and Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpaulovich committed Nov 6, 2019
1 parent ba5a218 commit 95058d2
Show file tree
Hide file tree
Showing 48 changed files with 640 additions and 125 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 2019-10-20 - 0.4.6

* #25 Cancellation Token fixed.
* Added XML docs.

## 2019-10-20 - 0.4.5

* #37 Validation for Null Requests added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup>
<PackageId>FluentMediator.Microsoft.Extensions.DependencyInjection</PackageId>
<Version>0.4.5</Version>
<Version>0.4.6</Version>
<Authors>Ivan Paulovich</Authors>
<Copyright>Ivan Paulovich</Copyright>
<Description>Microsoft Extensions for FluentMediator.</Description>
Expand All @@ -19,7 +20,7 @@
</PropertyGroup>

<ItemGroup Label="SourceLink">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19554-01" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Label="SourceLink">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@

namespace FluentMediator
{
/// <summary>
/// FluentMediatorExtensions
/// </summary>
public static class FluentMediatorExtensions
{
/// <summary>
/// Adds the FluentMediator
/// </summary>
/// <param name="services">The ServiceCollection</param>
/// <param name="setupAction">Builder</param>
/// <returns>The changed ServiceCollection</returns>
public static IServiceCollection AddFluentMediator(this IServiceCollection services, Action<IPipelineProviderBuilder> setupAction)
{
var pipelineProviderBuilder = new PipelineProviderBuilder();
Expand All @@ -18,6 +27,12 @@ public static IServiceCollection AddFluentMediator(this IServiceCollection servi
return services;
}

/// <summary>
/// Adds the FluentMediator
/// </summary>
/// <param name="services">The ServiceCollection</param>
/// <param name="setupAction">Builder</param>
/// <returns>The changed ServiceCollection</returns>
public static IServiceCollection AddSingletonFluentMediator(
this IServiceCollection services,
Action<IPipelineProviderBuilder> setupAction)
Expand All @@ -33,6 +48,12 @@ public static IServiceCollection AddFluentMediator(this IServiceCollection servi
return services;;
}

/// <summary>
/// Adds the FluentMediator
/// </summary>
/// <param name="services">The ServiceCollection</param>
/// <param name="setupAction">Builder</param>
/// <returns>The changed ServiceCollection</returns>
public static IServiceCollection AddScopedFluentMediator(
this IServiceCollection services,
Action<IPipelineProviderBuilder> setupAction)
Expand Down
5 changes: 3 additions & 2 deletions src/FluentMediator/FluentMediator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
<NullableReferenceTypes>true</NullableReferenceTypes>
<LangVersion>8.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup>
<PackageId>FluentMediator</PackageId>
<Version>0.4.5</Version>
<Version>0.4.6</Version>
<Authors>Ivan Paulovich</Authors>
<Copyright>Ivan Paulovich</Copyright>
<Description>FluentMediator is an unobtrusive library that allows developers to build custom pipelines for Commands, Queries and Events.</Description>
Expand All @@ -23,7 +24,7 @@
</PropertyGroup>

<ItemGroup Label="SourceLink">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19554-01" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Label="SourceLink">
Expand Down
5 changes: 5 additions & 0 deletions src/FluentMediator/GetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

namespace FluentMediator
{
/// <summary>
/// Retrieves a Handler Service from the Container
/// </summary>
/// <param name="serviceType"></param>
/// <returns></returns>
public delegate object GetService(Type serviceType);
}
14 changes: 11 additions & 3 deletions src/FluentMediator/IMediator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
using FluentMediator.Pipelines.CancellablePipelineAsync;
using FluentMediator.Pipelines.Pipeline;
using FluentMediator.Pipelines.PipelineAsync;

namespace FluentMediator
{
public interface IMediator : Pipelines.Pipeline.IMediator,
Pipelines.PipelineAsync.IMediator,
Pipelines.CancellablePipelineAsync.IMediator { }
/// <summary>
/// Publishes/Sends messages through the Pipelines
/// </summary>
public interface IMediator:
ISyncMediator,
IAsyncMediator,
ICancellableMediator { }
}
14 changes: 11 additions & 3 deletions src/FluentMediator/IPipelineProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
using FluentMediator.Pipelines.CancellablePipelineAsync;
using FluentMediator.Pipelines.Pipeline;
using FluentMediator.Pipelines.PipelineAsync;

namespace FluentMediator
{
public interface IPipelineProvider : Pipelines.Pipeline.IPipelineProvider,
Pipelines.PipelineAsync.IPipelineProvider,
Pipelines.CancellablePipelineAsync.IPipelineProvider { }
/// <summary>
/// Retrieves a Pipeline for a specific Message
/// </summary>
public interface IPipelineProvider:
ISyncPipelineProvider,
IAsyncPipelineProvider,
ICancellablePipelineProvider { }
}
23 changes: 20 additions & 3 deletions src/FluentMediator/IPipelineProviderBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
using FluentMediator.Pipelines;
using FluentMediator.Pipelines.CancellablePipelineAsync;
using FluentMediator.Pipelines.Pipeline;
using FluentMediator.Pipelines.PipelineAsync;

namespace FluentMediator
{
public interface IPipelineProviderBuilder : Pipelines.Pipeline.IPipelineProviderBuilder,
Pipelines.PipelineAsync.IPipelineProviderBuilder,
Pipelines.CancellablePipelineAsync.IPipelineProviderBuilder
/// <summary>
/// Builds pipelines for a specific message
/// </summary>
public interface IPipelineProviderBuilder:
ISyncPipelineProviderBuilder,
IAsyncPipelineProviderBuilder,
ICancellablePipelineProviderBuilder
{
/// <summary>
/// Begin building a pipeline for a specific message
/// </summary>
/// <typeparam name="TRequest">Message Type</typeparam>
/// <returns>A more specific PipelineBehavior</returns>
IPipelineBehavior<TRequest> On<TRequest>();

/// <summary>
/// Builds the pipeline
/// </summary>
/// <returns>An immutable Pipeline Provider</returns>
IPipelineProvider Build();
}
}
66 changes: 59 additions & 7 deletions src/FluentMediator/Mediator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@

namespace FluentMediator
{
/// <summary>
/// Publishes/Sends messages through the Pipelines
/// </summary>
public sealed class Mediator : IMediator
{
/// <summary>
/// Returns a service from the Container
/// </summary>
/// <value></value>
public GetService GetService { get; }
private IPipelineProvider _pipelines;

/// <summary>
/// Instantiate a Mediator
/// </summary>
/// <param name="getService">Service Provider</param>
/// <param name="pipelines">Pipeline Provider</param>
public Mediator(
GetService getService,
IPipelineProvider pipelines)
Expand All @@ -16,13 +28,18 @@ public sealed class Mediator : IMediator
_pipelines = pipelines;
}

/// <summary>
/// Publishes messages through the Pipeline
/// </summary>
/// <param name="request">Message</param>
/// <param name="pipelineName">An optional pipeline name</param>
public void Publish(object request, string? pipelineName = null)
{
if (request is null)
{
throw new NullRequestException("The request is null.");
}

if (pipelineName is string)
{
var pipeline = _pipelines.GetPipeline(pipelineName);
Expand All @@ -36,6 +53,13 @@ public void Publish(object request, string? pipelineName = null)
}
}

/// <summary>
/// Publishes messages through the Pipeline
/// </summary>
/// <param name="request">Message</param>
/// <param name="pipelineName">An optional pipeline name</param>
/// <typeparam name="TResult">The desired Typed result</typeparam>
/// <returns>The result object</returns>
public TResult Send<TResult>(object request, string? pipelineName = null)
{
if (request is null)
Expand All @@ -55,6 +79,12 @@ public TResult Send<TResult>(object request, string? pipelineName = null)
}
}

/// <summary>
/// Publishes messages through the Pipeline
/// </summary>
/// <param name="request">Message</param>
/// <param name="pipelineName">An optional pipeline name</param>
/// <returns>Task object</returns>
public async Task PublishAsync(object request, string? pipelineName = null)
{
if (request is null)
Expand All @@ -74,6 +104,13 @@ public async Task PublishAsync(object request, string? pipelineName = null)
}
}

/// <summary>
/// Publishes messages through the Pipeline
/// </summary>
/// <param name="request">Message</param>
/// <param name="pipelineName">An optional pipeline name</param>
/// <typeparam name="TResult">The desired Typed result</typeparam>
/// <returns>The result object</returns>
public async Task<TResult> SendAsync<TResult>(object request, string? pipelineName = null)
{
if (request is null)
Expand All @@ -93,7 +130,14 @@ public async Task<TResult> SendAsync<TResult>(object request, string? pipelineNa
}
}

public async Task PublishAsync(object request, CancellationToken ct, string? pipelineName = null)
/// <summary>
/// Publishes messages through the Pipeline
/// </summary>
/// <param name="request">Message</param>
/// <param name="cancellationToken">Cancellation Token to gracefully exit in middle of execution</param>
/// <param name="pipelineName">Optional Pipeline Name</param>
/// <returns>Task object</returns>
public async Task PublishAsync(object request, CancellationToken cancellationToken, string? pipelineName = null)
{
if (request is null)
{
Expand All @@ -103,16 +147,24 @@ public async Task PublishAsync(object request, CancellationToken ct, string? pip
if (pipelineName is string)
{
var pipeline = _pipelines.GetCancellablePipeline(pipelineName);
await pipeline.PublishAsync(GetService, request, ct);
await pipeline.PublishAsync(GetService, request, cancellationToken);
}
else
{
var pipeline = _pipelines.GetCancellablePipeline(request.GetType());
await pipeline.PublishAsync(GetService, request, ct);
await pipeline.PublishAsync(GetService, request, cancellationToken);
}
}

public async Task<TResult> SendAsync<TResult>(object request, CancellationToken ct, string? pipelineName = null)
/// <summary>
/// Sends messages through the Pipeline
/// </summary>
/// <param name="request">Message</param>
/// <param name="cancellationToken">Cancellation Token to gracefully exit in middle of execution</param>
/// <param name="pipelineName">Optional Pipeline Name</param>
/// <typeparam name="TResult">Result Type</typeparam>
/// <returns>Result object</returns>
public async Task<TResult> SendAsync<TResult>(object request, CancellationToken cancellationToken, string? pipelineName = null)
{
if (request is null)
{
Expand All @@ -122,12 +174,12 @@ public async Task<TResult> SendAsync<TResult>(object request, CancellationToken
if (pipelineName is string)
{
var pipeline = _pipelines.GetCancellablePipeline(pipelineName);
return await pipeline.SendAsync<TResult>(GetService, request, ct);
return await pipeline.SendAsync<TResult>(GetService, request, cancellationToken);
}
else
{
var pipeline = _pipelines.GetCancellablePipeline(request.GetType());
return await pipeline.SendAsync<TResult>(GetService, request, ct);
return await pipeline.SendAsync<TResult>(GetService, request, cancellationToken);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/FluentMediator/MediatorException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

namespace FluentMediator
{
/// <summary>
/// All Exceptions from FluentMediator are derived from MediatorException
/// </summary>
public class MediatorException : Exception
{
public MediatorException() { }
/// <summary>
/// Instantiate a MediatorException
/// </summary>
/// <param name="message">Error message</param>
/// <returns>The exception</returns>
public MediatorException(string message) : base(message) { }
public MediatorException(string message, System.Exception inner) : base(message, inner) { }
}
}
12 changes: 9 additions & 3 deletions src/FluentMediator/NullRequestException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
namespace FluentMediator
{
public class NullRequestException: MediatorException
/// <summary>
/// Occurs when the message is null
/// </summary>
public class NullRequestException : MediatorException
{
public NullRequestException() { }
/// <summary>
/// Instantiate an Exception
/// </summary>
/// <param name="message">The message</param>
/// <returns>An Exception instance</returns>
public NullRequestException(string message) : base(message) { }
public NullRequestException(string message, System.Exception inner) : base(message, inner) { }
}
}

0 comments on commit 95058d2

Please sign in to comment.