MediatR icon indicating copy to clipboard operation
MediatR copied to clipboard

How to add new ServiceCollectionExtension to the existing mediator?

Open ashk1860 opened this issue 5 years ago • 1 comments

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

ashk1860 avatar Nov 05 '20 15:11 ashk1860

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

MPapst avatar Dec 11 '20 06:12 MPapst