jbogard / MediatR.Extensions.Microsoft.DependencyInjection

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

Manage DI registrations #111

Open famda opened 2 years ago

famda commented 2 years ago

Hi @jbogard I have a question regarding this library.

Imagine the following scenario:

One assembly with a bunch of services; That assembly (classlib) is referenced by 2 applications; Some services on that assembly should be registered on the DI container of application1 and the other services for application2 (on this I've created an attribute to, with some reflection, identify which services belong to app1 and app2);

When I execute a request on the app1 it complains about not being able to resolve a dependency of a command that belongs to the app2.

(Unable to resolve service for type 'Service' while attempting to activate 'CreateCommand+CreateCommandHandler'.)')

I'm using the extension method that accepts an array of types and passing the types on each application. Here is a quick example of what I'm doing.

image

Is this a bug or am I missing something here?

Thanks in advance. ;)

famda commented 2 years ago

Maybe something like this? This seems to work.

image

But again, I'm not sure if this will bring me some issues in other places that I'm not aware of it now. :)