jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11.02k stars 1.16k forks source link

Why do we need to register IPipelineBehavior<,> manually with Scrutor's scan? #200

Closed FDUdannychen closed 6 years ago

FDUdannychen commented 6 years ago

Line 30 in the example of ASP.NET CORE

services.AddScoped(typeof(IPipelineBehavior<,>), typeof(GenericPipelineBehavior<,>));

IMO GenericPipelineBehavior<,> is registered by Scrutor's scan:

services.Scan(scan => scan
                .FromAssembliesOf(typeof(IMediator), typeof(Ping))
                .AddClasses()
                .AsImplementedInterfaces());

Unfortunately it isn't, which means line 30 is necessary. Why?

lilasquared commented 6 years ago

@FDUdannychen this might be due to it being a generic? I know with structuremap you have to explicitly call .ConnectImplementationsToTypesClosing()

jbogard commented 6 years ago

Open generics are treated differently in the ASP.NET Core container. Behaviors might not have any explicitly defined closed types, so T is not known until runtime.