jbogard / MediatR

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

How to add new ServiceCollectionExtension to the existing mediator? #576

Closed ashk1860 closed 2 years ago

ashk1860 commented 4 years ago

HI Jimmy Thanks for the greate tool. I really enjoy using it is there any way to add new ServiceCollectionExtension to the existing mediator? I try to find it in the documentations. but unfortunately couldn't find anything. I have a mediator which I am making at application start and using it. during the usage of the application, based on the user choices I need to add new ServiceCollectionExtension to it. since I don't know how, i have to make another instance of mediator. Thank you in advanced

MPapst commented 3 years ago

Hi ashk,

you can just recall services.AddMediatR(...), it will take care by only adding the IMediator service when it has not been registered before. See https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/blob/1ed8e74ad35b89d1ef460b8433af2b92bee8bcfd/src/MediatR.Extensions.Microsoft.DependencyInjection/Registration/ServiceRegistrar.cs#L216