jbogard / MediatR.Extensions.Microsoft.DependencyInjection

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

Calling AddMediatR multiple times #84

Closed sandord closed 4 years ago

sandord commented 4 years ago

The AddMediatR extension method can be called multiple times without resulting in an immediately thrown exception.

I'm not sure if it's a common thing to check for this kind of 'abuse' but I guess it could lead to confusing results if someone accidentally called it twice.

When I call AddMediatR twice, a number of services end up registered in the container twice as well.

When I look at OptionsServiceCollectionExtensions.AddOptions from MS for example, I see that they use services.TryAdd so their AddOptions method can be called multiple times without a problem.

This could sound like desired behaviour for MediatR but then rises the question: what would it do when two configuration actions were supplied?

sandord commented 4 years ago

Dang, I just saw https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/pull/77.