Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Add multiple request pre/post processors #59

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ private static void AddMediatRClasses(IServiceCollection services, IEnumerable<A

ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>), services, assembliesToScan, false);
ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>), services, assembliesToScan, true);
ConnectImplementationsToTypesClosing(typeof(IRequestPreProcessor<>), services, assembliesToScan, false);
ConnectImplementationsToTypesClosing(typeof(IRequestPostProcessor<,>), services, assembliesToScan, false);
ConnectImplementationsToTypesClosing(typeof(IRequestPreProcessor<>), services, assembliesToScan, true);
ConnectImplementationsToTypesClosing(typeof(IRequestPostProcessor<,>), services, assembliesToScan, true);

var multiOpenInterfaces = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ public Task Process(TRequest request, CancellationToken cancellationToken)
}
}

public class FirstConcretePreProcessor : IRequestPreProcessor<Ping>
{
private readonly Logger _output;

public FirstConcretePreProcessor(Logger output)
{
_output = output;
}
public Task Process(Ping request, CancellationToken cancellationToken)
{
_output.Messages.Add("First concrete pre processor");
return Task.FromResult(0);
}
}

public class NextPreProcessor<TRequest> : IRequestPreProcessor<TRequest>
{
private readonly Logger _output;
Expand All @@ -140,6 +155,22 @@ public Task Process(TRequest request, CancellationToken cancellationToken)
return Task.FromResult(0);
}
}

public class NextConcretePreProcessor : IRequestPreProcessor<Ping>
{
private readonly Logger _output;

public NextConcretePreProcessor(Logger output)
{
_output = output;
}
public Task Process(Ping request, CancellationToken cancellationToken)
{
_output.Messages.Add("Next concrete pre processor");
return Task.FromResult(0);
}
}

public class FirstPostProcessor<TRequest, TResponse> : IRequestPostProcessor<TRequest, TResponse>
{
private readonly Logger _output;
Expand All @@ -155,6 +186,21 @@ public Task Process(TRequest request, TResponse response)
}
}

public class FirstConcretePostProcessor : IRequestPostProcessor<Ping, Pong>
{
private readonly Logger _output;

public FirstConcretePostProcessor(Logger output)
{
_output = output;
}
public Task Process(Ping request, Pong response)
{
_output.Messages.Add("First concrete post processor");
return Task.FromResult(0);
}
}

public class NextPostProcessor<TRequest, TResponse> : IRequestPostProcessor<TRequest, TResponse>
{
private readonly Logger _output;
Expand All @@ -170,6 +216,21 @@ public Task Process(TRequest request, TResponse response)
}
}

public class NextConcretePostProcessor : IRequestPostProcessor<Ping, Pong>
{
private readonly Logger _output;

public NextConcretePostProcessor(Logger output)
{
_output = output;
}
public Task Process(Ping request, Pong response)
{
_output.Messages.Add("Next concrete post processor");
return Task.FromResult(0);
}
}

[Fact]
public async Task Should_wrap_with_behavior()
{
Expand All @@ -191,9 +252,13 @@ public async Task Should_wrap_with_behavior()
{
"Outer before",
"Inner before",
"First concrete pre processor",
"Next concrete pre processor",
"First pre processor",
"Next pre processor",
"Handler",
"First concrete post processor",
"Next concrete post processor",
"First post processor",
"Next post processor",
"Inner after",
Expand Down Expand Up @@ -223,9 +288,13 @@ public async Task Should_wrap_generics_with_behavior()
{
"Outer generic before",
"Inner generic before",
"First concrete pre processor",
"Next concrete pre processor",
"First pre processor",
"Next pre processor",
"Handler",
"First concrete post processor",
"Next concrete post processor",
"First post processor",
"Next post processor",
"Inner generic after",
Expand All @@ -250,9 +319,13 @@ public async Task Should_pick_up_pre_and_post_processors()

output.Messages.ShouldBe(new[]
{
"First concrete pre processor",
"Next concrete pre processor",
"First pre processor",
"Next pre processor",
"Handler",
"First concrete post processor",
"Next concrete post processor",
"First post processor",
"Next post processor",
});
Expand Down