Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AutoRegisterRequestProcessors to include all implementations #989

Merged
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
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
Loading