question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pre and Post Processors handled multiple times (version 8)

See original GitHub issue

EDIT: Solution from @lilasquared


Am I doing something wrong here? This happens using pre and post processors

public class MediatRInstaller : IInstaller
    {
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddMediatR(typeof(CreateCustomerCommand).Assembly);

            services.AddScoped(typeof(IRequestPostProcessor<,>), typeof(LoggingBehavior<,>));
        }
    }
public class LoggingBehavior<TRequest, TResponse> : IRequestPostProcessor<TRequest, TResponse>
    {
        public Task Process(TRequest request, TResponse response, CancellationToken cancellationToken)
        {
            Log.Information($"Handled {typeof(TRequest).DeclaringType?.Name ?? typeof(TRequest).Name}");

            return Task.CompletedTask;
        }
    }

After one web request:

08 Jan 2020 10:07:06.507 Handled GetCustomersQuery
08 Jan 2020 10:07:00.679 Handled GetCustomersQuery

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
lilasquaredcommented, Jan 8, 2020

the AddMediatR method already connects implementations to types closing the pre and post request processors, so you do not need this line services.AddScoped(typeof(IRequestPostProcessor<,>), typeof(LoggingBehavior<,>));

you only need to register actual pipeline behaviors manually.

1reaction
lilasquaredcommented, Jan 21, 2020

in fact, the main wiki (https://github.com/jbogard/MediatR/wiki#aspnet-core) DOES have this link

ASP.NET Core If you’re using ASP.NET Core then you can skip the configuration and use MediatR’s MediatR.Extensions.Microsoft.DependencyInjection package which includes a IServiceCollection.AddMediatR(Assembly) extension method, allowing you to register all handlers and pre/post-processors in a given assembly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deconfusing Pre- and Post-processing
Figure 3: PostCSS gives us much more possibilities. We can use everything we had with Sass (Variables, Nesting and Mixins), some of them...
Read more >
JMeter: Application of Pre-Processor and Post-Processor
Pre and Post Processors execution time isn't included into test reports. If you want to change this behavior you need to use Transaction ......
Read more >
Using Post Processor In JMeter (Regular Expression ...
In this tutorial, you will learn to use JMeter Post Processor such as Regular Expression Extractor, BeanShell, JDBC, Boundry Extractor etc.
Read more >
Java Preprocessor and Postprocessor
Under Postprocessor, configure one of the following: For Java, you can configure multiple Postprocessors. This is supported for Integration/Orchestration ...
Read more >
Pre/Post-Processor Design Patterns
Mendix developers have multiple choices when it comes to implementing pre- / post-processors. This document explores four pre-processor and post ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found