Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
455dc67
commit 97e06ee
Showing
21 changed files
with
121 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
using System.Threading.Tasks; | ||
using Handyman.Mediator.Pipeline; | ||
|
||
namespace Handyman.Mediator | ||
{ | ||
public interface IEventFilter<TEvent> | ||
where TEvent : IEvent | ||
public interface IEventFilter<in TEvent> | ||
{ | ||
Task Execute(EventPipelineContext<TEvent> context, EventFilterExecutionDelegate next); | ||
Task Execute(TEvent @event, IEventFilterContext context, EventFilterExecutionDelegate next); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Threading; | ||
|
||
namespace Handyman.Mediator | ||
{ | ||
public interface IEventFilterContext | ||
{ | ||
CancellationToken CancellationToken { get; set; } | ||
IServiceProvider ServiceProvider { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Lamar; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Shouldly; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Handyman.Mediator.Tests | ||
{ | ||
public class EventFilterTests | ||
{ | ||
[Fact] | ||
public async Task ShouldExecuteFilters() | ||
{ | ||
// using Lamar for dependency injection as it has support for constrained open generics | ||
|
||
var container = new Container(services => services.AddTransient<IEventFilter<IMarker>, Filter>()); | ||
|
||
await new Mediator(container).Publish(new Event()); | ||
|
||
Filter.Executed.ShouldBeTrue(); | ||
} | ||
|
||
private class Event : IEvent, IMarker { } | ||
|
||
private interface IMarker { } | ||
|
||
private class Filter : IEventFilter<IMarker> | ||
{ | ||
public static bool Executed; | ||
|
||
public Task Execute(IMarker @event, IEventFilterContext context, EventFilterExecutionDelegate next) | ||
{ | ||
Executed = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 24 additions & 16 deletions
40
src/Handyman.Mediator/tests/Handyman.Mediator.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net472;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1</TargetFrameworks> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>net472;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" /> | ||
<PackageReference Include="Shouldly" Version="3.0.2" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Lamar" Version="4.3.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" /> | ||
<PackageReference Include="Shouldly" Version="3.0.2" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\Handyman.Mediator.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' "> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFramework)' != 'net472' "> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.7" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\Handyman.Mediator.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters