jbogard / MediatR.Extensions.Microsoft.DependencyInjection

MediatR extensions for Microsoft.Extensions.DependencyInjection
MIT License
327 stars 90 forks source link

Help Required #50

Closed abomadi closed 5 years ago

abomadi commented 5 years ago

Im trying to use MediatR across multiple class libraries as the following :

- Project 1 >> Raise INotification<EventTest>
- Project 2 >> Handle INotificationHandler<EventTest>
- Project 3 >> Handle INotificationHandler<EventTest>

if i create handler withing the same class library it works well, however Project 2 and 3 handlers are never triggered, i register all the above using Microsoft DI and Scrutor any help plz ?

lilasquared commented 5 years ago

Most likely you are not scanning project 2 or 3 during start up. Please share the code you are using to register your handlers.

abomadi commented 5 years ago

@lilasquared

services.AddMediatR();
            services.Scan(scan => scan
             .FromAssembliesOf(typeof(IMediator), typeof(TestEvent), typeof(TestCommand)
             , typeof(TestEventHandler))
             .AddClasses()
             .AsImplementedInterfaces());

i call all the required assemblies here FromAssemblies, also all handlers are registered as services.AddScoped<IRequestHandler<TestCommand>, TestCommandHandler>();

lilasquared commented 5 years ago

Doesn't the AddMediatR method accept assemblies to scan as parameters? Have you tried that? If you are using the MicrosoftDI MediatR extension it should handle registering the handlers for you.

abomadi commented 5 years ago

@lilasquared Yes it does tried both cases actually, as the following:

services.AddMediatR(typeof(IMediator), typeof(TestEvent), typeof(TestCommand), typeof(TestEventHandler));
services.AddScoped<IRequestHandler<TestCommand>, TestCommandHandler>();

all projects are referenced to this one and this is being called on Startup

lilasquared commented 5 years ago

It's going to be hard to help out with this without more info about the project. Are you able to create a small sample project that replicates the behavior that you can share?

abomadi commented 5 years ago

@lilasquared here is a sample project MediatRTest

jbogard commented 5 years ago

I think this is in the wrong repository, if you're using the DI extension.

jbogard commented 5 years ago

You shouldn't need to register notification handlers, AddMediatR does that already.