Skip to content

Commit

Permalink
Merge pull request #989 from hisuwh/bug/not-all-pre-post-processors-r…
Browse files Browse the repository at this point in the history
…egistered

Fix AutoRegisterRequestProcessors to include all implementations
  • Loading branch information
jbogard committed Jan 17, 2024
2 parents 6baaeef + cccd378 commit 88c4d73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/MediatR/Registration/ServiceRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static void AddMediatRClasses(IServiceCollection services, MediatRService

if (configuration.AutoRegisterRequestProcessors)
{
ConnectImplementationsToTypesClosing(typeof(IRequestPreProcessor<>), services, assembliesToScan, false, configuration);
ConnectImplementationsToTypesClosing(typeof(IRequestPostProcessor<,>), services, assembliesToScan, false, configuration);
ConnectImplementationsToTypesClosing(typeof(IRequestPreProcessor<>), services, assembliesToScan, true, configuration);
ConnectImplementationsToTypesClosing(typeof(IRequestPostProcessor<,>), services, assembliesToScan, true, configuration);
}

var multiOpenInterfaces = new List<Type>
Expand Down
13 changes: 10 additions & 3 deletions test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ public void Should_handle_open_behaviors_registration_from_a_single_type()
}

[Fact]
public void Should_auto_register_processors_when_configured()
public void Should_auto_register_processors_when_configured_including_all_concrete_types()
{
var cfg = new MediatRServiceConfiguration
{
Expand All @@ -864,8 +864,15 @@ public void Should_auto_register_processors_when_configured()

var provider = services.BuildServiceProvider();

provider.GetServices(typeof(IRequestPreProcessor<Ping>)).Count().ShouldBeGreaterThan(0);
provider.GetServices(typeof(IRequestPostProcessor<Ping, Pong>)).Count().ShouldBeGreaterThan(0);
var preProcessors = provider.GetServices(typeof(IRequestPreProcessor<Ping>)).ToList();
preProcessors.Count.ShouldBeGreaterThan(0);
preProcessors.ShouldContain(p => p != null && p.GetType() == typeof(FirstConcretePreProcessor));
preProcessors.ShouldContain(p => p != null && p.GetType() == typeof(NextConcretePreProcessor));

var postProcessors = provider.GetServices(typeof(IRequestPostProcessor<Ping, Pong>)).ToList();
postProcessors.Count.ShouldBeGreaterThan(0);
postProcessors.ShouldContain(p => p != null && p.GetType() == typeof(FirstConcretePostProcessor));
postProcessors.ShouldContain(p => p != null && p.GetType() == typeof(NextConcretePostProcessor));
}


Expand Down

0 comments on commit 88c4d73

Please sign in to comment.