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?
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 useservices.TryAdd
so theirAddOptions
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?