Skip to content

Commit

Permalink
Initial named pipeline support #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpaulovich committed Oct 20, 2019
1 parent ab93dee commit a09ebef
Show file tree
Hide file tree
Showing 52 changed files with 358 additions and 337 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 2019-10-20 - 0.4.0

* Refactoring

## 2019-10-19 - 0.3.3

* #31 Support Scoped & Transient Lifetime.
Expand Down
File renamed without changes
8 changes: 4 additions & 4 deletions samples/PingPong/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class Program
static void Main(string[] args)
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddFluentMediator(m =>
serviceCollection.AddFluentMediator(builder =>
{
m.On<PingRequest>().Pipeline()
builder.On<PingRequest>().Pipeline()
.Call<PingHandler>((handler, req) => handler.MyMethod(req))
.Call<PingHandler>((handler, req) => handler.MyLongMethod(req));
m.On<PingRequest>().AsyncPipeline()
builder.On<PingRequest>().PipelineAsync()
.Call<PingHandler>(async(handler, req) => await handler.MyMethodAsync(req));
m.On<PingRequest>().CancellablePipeline()
builder.On<PingRequest>().CancellablePipelineAsync()
.Call<PingHandler>(async(handler, req, ct) => await handler.MyMethodAsync(req, ct));
});
serviceCollection.AddScoped<PingHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@

<PropertyGroup>
<PackageId>FluentMediator.Microsoft.Extensions.DependencyInjection</PackageId>
<Version>0.3.3</Version>
<Version>0.4.0</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>
<PackageDescription>We will not require you to add dependencies into your domain or to implement frameworks interfaces in your event handlers. Finally a really loosely coupled mediator library was born.</PackageDescription>
<Description>Microsoft Extensions for FluentMediator.</Description>
<PackageDescription>Microsoft Extensions for FluentMediator.</PackageDescription>
<PackageTags>fluent-design;mediator-pattern;ddd-cqrs;message-bus;event-sourcing;event-driven;chain-of-responsibility;chain-methods;pipelines;dotnet-core;craftmanship;tdd;csharp;pipeline-framework;fluent-interface;event-handlers</PackageTags>
<IsPackable>true</IsPackable>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/ivanpaulovich/FluentMediator</RepositoryUrl>
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>

<ItemGroup>
<None Include="icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup Label="SourceLink">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>
Expand All @@ -42,4 +36,11 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
<None Include="../../docs/icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ namespace FluentMediator
{
public static class FluentMediatorExtensions
{
public static IServiceCollection AddFluentMediator(this IServiceCollection services, Action<IPipelinesBuilder> setupAction)
public static IServiceCollection AddFluentMediator(this IServiceCollection services, Action<IPipelineProviderBuilder> setupAction)
{
var pipelinesBuilder = new PipelinesBuilder();
setupAction(pipelinesBuilder);
var pipelines = pipelinesBuilder.Build();
var pipelineProviderBuilder = new PipelineProviderBuilder();
setupAction(pipelineProviderBuilder);
var pipelineProvider = pipelineProviderBuilder.Build();

services.AddTransient<GetService>(c => c.GetService);
services.AddTransient(c => pipelines);
services.AddTransient(c => pipelineProvider);
services.AddTransient<IMediator, Mediator>();

return services;
}

public static IServiceCollection AddSingletonFluentMediator(
this IServiceCollection services,
Action<IPipelinesBuilder> setupAction)
Action<IPipelineProviderBuilder> setupAction)
{
var pipelinesBuilder = new PipelinesBuilder();
setupAction(pipelinesBuilder);
var pipelines = pipelinesBuilder.Build();
var pipelineProviderBuilder = new PipelineProviderBuilder();
setupAction(pipelineProviderBuilder);
var pipelineProvider = pipelineProviderBuilder.Build();

services.AddSingleton(c => pipelines);
services.AddSingleton(c => pipelineProvider);
services.AddSingleton<GetService>(c => c.GetService);
services.AddSingleton<IMediator, Mediator>();

Expand All @@ -35,13 +35,13 @@ public static IServiceCollection AddFluentMediator(this IServiceCollection servi

public static IServiceCollection AddScopedFluentMediator(
this IServiceCollection services,
Action<IPipelinesBuilder> setupAction)
Action<IPipelineProviderBuilder> setupAction)
{
var pipelinesBuilder = new PipelinesBuilder();
setupAction(pipelinesBuilder);
var pipelines = pipelinesBuilder.Build();
var pipelineProviderBuilder = new PipelineProviderBuilder();
setupAction(pipelineProviderBuilder);
var pipelineProvider = pipelineProviderBuilder.Build();

services.AddScoped(c => pipelines);
services.AddScoped(c => pipelineProvider);
services.AddScoped<GetService>(c => c.GetService);
services.AddScoped<IMediator, Mediator>();

Expand Down
19 changes: 10 additions & 9 deletions src/FluentMediator/FluentMediator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@

<PropertyGroup>
<PackageId>FluentMediator</PackageId>
<Version>0.3.2</Version>
<Version>0.4.0</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>
<PackageDescription>We will not require you to add dependencies into your domain or to implement frameworks interfaces in your event handlers. Finally a really loosely coupled mediator library was born.</PackageDescription>
<PackageDescription>FluentMediator is an unobtrusive library that allows developers to build custom pipelines for Commands, Queries and Events.</PackageDescription>
<PackageTags>fluent-design;mediator-pattern;ddd-cqrs;message-bus;event-sourcing;event-driven;chain-of-responsibility;chain-methods;pipelines;dotnet-core;craftmanship;tdd;csharp;pipeline-framework;fluent-interface;event-handlers</PackageTags>
<IsPackable>true</IsPackable>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/ivanpaulovich/FluentMediator</RepositoryUrl>
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>

<ItemGroup>
<None Include="icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup Label="SourceLink">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>
Expand All @@ -37,4 +31,11 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<None Include="../../docs/icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>
11 changes: 3 additions & 8 deletions src/FluentMediator/IMediator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using FluentMediator.Pipelines.AsyncPipeline;
using FluentMediator.Pipelines.CancellablePipeline;
using FluentMediator.Pipelines.Pipeline;

namespace FluentMediator
{
public interface IMediator : IPipelineMediator, IAsyncPipelineMediator, ICancellablePipelineMediator
{
GetService GetService { get; }
}
public interface IMediator : Pipelines.Pipeline.IMediator,
Pipelines.PipelineAsync.IMediator,
Pipelines.CancellablePipelineAsync.IMediator { }
}
6 changes: 6 additions & 0 deletions src/FluentMediator/IPipelineProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace FluentMediator
{
public interface IPipelineProvider : Pipelines.Pipeline.IPipelineProvider,
Pipelines.PipelineAsync.IPipelineProvider,
Pipelines.CancellablePipelineAsync.IPipelineProvider { }
}
12 changes: 12 additions & 0 deletions src/FluentMediator/IPipelineProviderBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using FluentMediator.Pipelines;

namespace FluentMediator
{
public interface IPipelineProviderBuilder : Pipelines.Pipeline.IPipelineProviderBuilder,
Pipelines.PipelineAsync.IPipelineProviderBuilder,
Pipelines.CancellablePipelineAsync.IPipelineProviderBuilder
{
IPipelineBehavior<TRequest> On<TRequest>();
IPipelineProvider Build();
}
}
14 changes: 0 additions & 14 deletions src/FluentMediator/IPipelines.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/FluentMediator/IPipelinesBuilder.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/FluentMediator/Mediator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace FluentMediator
public sealed class Mediator : IMediator
{
public GetService GetService { get; }
private IPipelines _pipelines;
private IPipelineProvider _pipelines;

public Mediator(
GetService getService,
IPipelines pipelines)
IPipelineProvider pipelines)
{
GetService = getService;
_pipelines = pipelines;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
using System;
using FluentMediator.Pipelines;
using FluentMediator.Pipelines.AsyncPipeline;
using FluentMediator.Pipelines.CancellablePipeline;
using FluentMediator.Pipelines.CancellablePipelineAsync;
using FluentMediator.Pipelines.Pipeline;
using FluentMediator.Pipelines.PipelineAsync;

namespace FluentMediator
{
internal sealed class PipelinesProvider : IPipelines
internal sealed class PipelineProvider : IPipelineProvider
{
private readonly IPipelineCollection<IPipeline> _pipelineCollection;
private readonly IPipelineCollection<IAsyncPipeline> _asyncPipelineCollection;
private readonly IPipelineCollection<ICancellablePipeline> _cancellablePipelineCollection;
private readonly IPipelineCollection<IPipelineAsync> _asyncPipelineCollection;
private readonly IPipelineCollection<ICancellablePipelineAsync> _cancellablePipelineCollection;

public PipelinesProvider(
public PipelineProvider(
IPipelineCollection<IPipeline> pipelineCollection,
IPipelineCollection<IAsyncPipeline> asyncPipelineCollection,
IPipelineCollection<ICancellablePipeline> cancellablePipelineCollection)
IPipelineCollection<IPipelineAsync> asyncPipelineCollection,
IPipelineCollection<ICancellablePipelineAsync> cancellablePipelineCollection)
{
_pipelineCollection = pipelineCollection;
_asyncPipelineCollection = asyncPipelineCollection;
_cancellablePipelineCollection = cancellablePipelineCollection;
}

public IAsyncPipeline GetAsyncPipeline(Type requestType)
public IPipelineAsync GetAsyncPipeline(Type requestType)
{
return _asyncPipelineCollection.Get(requestType);
}

public ICancellablePipeline GetCancellablePipeline(Type requestType)
public ICancellablePipelineAsync GetCancellablePipeline(Type requestType)
{
return _cancellablePipelineCollection.Get(requestType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using FluentMediator.Pipelines;
using FluentMediator.Pipelines.AsyncPipeline;
using FluentMediator.Pipelines.CancellablePipeline;
using FluentMediator.Pipelines.CancellablePipelineAsync;
using FluentMediator.Pipelines.Pipeline;
using FluentMediator.Pipelines.PipelineAsync;

namespace FluentMediator
{
public sealed class PipelinesBuilder : IPipelinesBuilder
public sealed class PipelineProviderBuilder : IPipelineProviderBuilder
{
private ICollection<IPipelineBuilder> _pipelineBuilderCollection { get; }
private ICollection<IAsyncPipelineBuilder> _asyncPipelineBuilderCollection { get; }
private ICollection<ICancellablePipelineBuilder> _cancellablePipelineBuilderCollection { get; }
private ICollection<IPipelineAsyncBuilder> _asyncPipelineBuilderCollection { get; }
private ICollection<ICancellablePipelineAsyncBuilder> _cancellablePipelineBuilderCollection { get; }

public PipelinesBuilder()
public PipelineProviderBuilder()
{
_pipelineBuilderCollection = new Collection<IPipelineBuilder>();
_asyncPipelineBuilderCollection = new Collection<IAsyncPipelineBuilder>();
_cancellablePipelineBuilderCollection = new Collection<ICancellablePipelineBuilder>();
_asyncPipelineBuilderCollection = new Collection<IPipelineAsyncBuilder>();
_cancellablePipelineBuilderCollection = new Collection<ICancellablePipelineAsyncBuilder>();
}

public IPipelineBehavior<TRequest> On<TRequest>()
Expand All @@ -26,49 +26,49 @@ public IPipelineBehavior<TRequest> On<TRequest>()
return behavior;
}

public IPipelineBuilder Add(IPipelineBuilder pipeline)
public IPipelineBuilder Add(IPipelineBuilder pipelineBuilder)
{
_pipelineBuilderCollection.Add(pipeline);
return pipeline;
_pipelineBuilderCollection.Add(pipelineBuilder);
return pipelineBuilder;
}

public IAsyncPipelineBuilder Add(IAsyncPipelineBuilder asyncPipeline)
public IPipelineAsyncBuilder Add(IPipelineAsyncBuilder pipelineBuilder)
{
_asyncPipelineBuilderCollection.Add(asyncPipeline);
return asyncPipeline;
_asyncPipelineBuilderCollection.Add(pipelineBuilder);
return pipelineBuilder;
}

public ICancellablePipelineBuilder Add(ICancellablePipelineBuilder cancellablePipeline)
public ICancellablePipelineAsyncBuilder Add(ICancellablePipelineAsyncBuilder pipelineBuilder)
{
_cancellablePipelineBuilderCollection.Add(cancellablePipeline);
return cancellablePipeline;
_cancellablePipelineBuilderCollection.Add(pipelineBuilder);
return pipelineBuilder;
}

public IPipelines Build()
public IPipelineProvider Build()
{
var pipelineCollection = new PipelineCollection<IPipeline>();
var asyncPipelineCollection = new PipelineCollection<IAsyncPipeline>();
var cancellablePipelineCollection = new PipelineCollection<ICancellablePipeline>();
var asyncPipelineCollection = new PipelineCollection<IPipelineAsync>();
var cancellablePipelineCollection = new PipelineCollection<ICancellablePipelineAsync>();

foreach (var item in _pipelineBuilderCollection)
{
var pipeline = item.Build();
pipelineCollection.Add(pipeline.RequestType, pipeline);
pipelineCollection.Add(pipeline);
}

foreach (var item in _asyncPipelineBuilderCollection)
{
var pipeline = item.Build();
asyncPipelineCollection.Add(pipeline.RequestType, pipeline);
asyncPipelineCollection.Add(pipeline);
}

foreach (var item in _cancellablePipelineBuilderCollection)
{
var pipeline = item.Build();
cancellablePipelineCollection.Add(pipeline.RequestType, pipeline);
cancellablePipelineCollection.Add(pipeline);
}

return new PipelinesProvider(
return new PipelineProvider(
pipelineCollection,
asyncPipelineCollection,
cancellablePipelineCollection
Expand Down

0 comments on commit a09ebef

Please sign in to comment.