jbogard / MediatR.Extensions.Microsoft.DependencyInjection

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

Add ability to specify custom IMediator implementation #42

Closed thiagolunardi closed 5 years ago

thiagolunardi commented 5 years ago

I wrote my custom IMediator implementation, and now I'd like to keep using MediatR.Extensions.Microsoft.DependencyInjection but specifying my custom implementation.

Something like

services.AddMediatR().Using<MyCustomMediator>();

Or even:

services.AddMediatR(cfg => cfg.Using<MyCustomMediator>());

By that, I will keep having all benefits of MediatR.Extensions.Microsoft.DependencyInjection, plus flexibility.

jbogard commented 5 years ago

What does this class do?

On Fri, Sep 7, 2018 at 3:43 AM Thiago Lunardi notifications@github.com wrote:

I wrote my custom IMediator implementation, and now I'd like to keep using MediatR.Extensions.Microsoft.DependencyInjection but specifying my custom implementation.

Something like

services.AddMediatR().Using();

Or even:

services.AddMediatR(cfg => cfg.Using());

By that, I will keep having all benefits of MediatR.Extensions.Microsoft.DependencyInjection, plus flexibility.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/issues/42, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMjNIE8EXr0SO6bztBYwIWJHhbwTtks5uYjGpgaJpZM4Wea_7 .

thiagolunardi commented 5 years ago

The class MyCustomMediator just implements IMediator, and during the app bootstrap - using dotnet core - I'd like to use this extension to inject all dependencies, but with the option to use my custom implementation.

jbogard commented 5 years ago

But what does your class provide that the built in one does not?

On Mon, Sep 10, 2018 at 1:25 AM Thiago Lunardi notifications@github.com wrote:

The class MyCustomMediator just implements IMediator, and during the app bootstrap - using dotnet core - I'd like to use this extension to inject all dependencies, but with the option to use my custom implementation.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/issues/42#issuecomment-419801897, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMrezEG8v-HpNdJ-BDKSd4gM5YxPUks5uZgXFgaJpZM4Wea_7 .

thiagolunardi commented 5 years ago

Well, as the first moment, it doesn't matter. But just for context, I created my own implementation for sake of testings.

The IMediator is a public interface, which means I can have my own implementation of it and will be really nice if I can use the same extension to also inject this custom implementation.

jbogard commented 5 years ago

If it’s for testing can’t you already replace the implementation in the service collection? You can remove one item and add another straight on that object?

On Wed, Sep 12, 2018 at 3:14 AM Thiago Lunardi notifications@github.com wrote:

Well, as the first moment, it doesn't matter. But just for context, I created my own implementation for sake of testings.

The IMediator is a public interface, which means I can have my own implementation of it and will be really nice if I can use the same extension to also inject this custom implementation.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/issues/42#issuecomment-420555368, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMg0s6eQp_Xe45LNW1Radd7BTIq7Lks5uaMJ5gaJpZM4Wea_7 .

thiagolunardi commented 5 years ago

As I said, really doesn't matter what anyone custom implementation does, what is being asked is for an option for, if I have my own then I'd like to register it instead of the default one using this nice extension.

Adding more info - as I have it just now - I customized it to do some logs, using X-HttpRequest-Id and adding it as a Singleton when I'm using it in a non-web Host.

jbogard commented 5 years ago

Are you prevented from registering a custom one today?

On Thu, Sep 13, 2018 at 9:51 AM Thiago Lunardi notifications@github.com wrote:

As I said, really doesn't matter what anyone custom implementation does, what is being asked is for an option for, if I have my own then I'd like to register it instead of the default one using this nice extension.

Adding more info - as I have it just now - I customized it to do some logs, using X-HttpRequest-Id and adding it as a Singleton when I'm using it in a non-web Host.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/issues/42#issuecomment-421035123, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMj5gb3VbAp0hTtGbR_032NoV-SlOks5uanDsgaJpZM4Wea_7 .

thiagolunardi commented 5 years ago

Using this extension as is, it's not possible.

Sent from Ninehttp://www.9folders.com/


From: Jimmy Bogard notifications@github.com Sent: Thursday, September 13, 2018 17:17 To: jbogard/MediatR.Extensions.Microsoft.DependencyInjection Cc: Thiago Lunardi; Author Subject: Re: [jbogard/MediatR.Extensions.Microsoft.DependencyInjection] Add ability to specify custom IMediator implementation (#42)

Are you prevented from registering a custom one today?

On Thu, Sep 13, 2018 at 9:51 AM Thiago Lunardi notifications@github.com wrote:

As I said, really doesn't matter what anyone custom implementation does, what is being asked is for an option for, if I have my own then I'd like to register it instead of the default one using this nice extension.

Adding more info - as I have it just now - I customized it to do some logs, using X-HttpRequest-Id and adding it as a Singleton when I'm using it in a non-web Host.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/issues/42#issuecomment-421035123, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMj5gb3VbAp0hTtGbR_032NoV-SlOks5uanDsgaJpZM4Wea_7 .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjbogard%2FMediatR.Extensions.Microsoft.DependencyInjection%2Fissues%2F42%23issuecomment-421044086&data=02%7C01%7C%7C92b1d1ba19eb43aac6b408d6198c06b6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636724486529011654&sdata=pIQNkfuzfma0IWFHg%2BkdiOlzkktgztfvsrtni%2BOOoUI%3D&reserved=0, or mute the threadhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAFLVK_QAxxv0M3CXFtOJ2NARe7Ye5Bxeks5uancLgaJpZM4Wea_7&data=02%7C01%7C%7C92b1d1ba19eb43aac6b408d6198c06b6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636724486529011654&sdata=Q2Tg4Ef1%2FA2NOG9Rlg%2Bobz8yolHKI1PTaZX4TaczSa4%3D&reserved=0.

jbogard commented 5 years ago

Oh I found a built-in way:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.extensions.servicecollectiondescriptorextensions.replace

We don’t need anything custom, you can already remove and replace any registration.

TIL

On Thu, Sep 13, 2018 at 12:06 PM Thiago Lunardi notifications@github.com wrote:

Using this extension as is, it's not possible.

Sent from Ninehttp://www.9folders.com/


From: Jimmy Bogard notifications@github.com Sent: Thursday, September 13, 2018 17:17 To: jbogard/MediatR.Extensions.Microsoft.DependencyInjection Cc: Thiago Lunardi; Author Subject: Re: [jbogard/MediatR.Extensions.Microsoft.DependencyInjection] Add ability to specify custom IMediator implementation (#42)

Are you prevented from registering a custom one today?

On Thu, Sep 13, 2018 at 9:51 AM Thiago Lunardi notifications@github.com wrote:

As I said, really doesn't matter what anyone custom implementation does, what is being asked is for an option for, if I have my own then I'd like to register it instead of the default one using this nice extension.

Adding more info - as I have it just now - I customized it to do some logs, using X-HttpRequest-Id and adding it as a Singleton when I'm using it in a non-web Host.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub < https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/issues/42#issuecomment-421035123 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AAGYMj5gb3VbAp0hTtGbR_032NoV-SlOks5uanDsgaJpZM4Wea_7

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub< https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjbogard%2FMediatR.Extensions.Microsoft.DependencyInjection%2Fissues%2F42%23issuecomment-421044086&data=02%7C01%7C%7C92b1d1ba19eb43aac6b408d6198c06b6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636724486529011654&sdata=pIQNkfuzfma0IWFHg%2BkdiOlzkktgztfvsrtni%2BOOoUI%3D&reserved=0>, or mute the thread< https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAFLVK_QAxxv0M3CXFtOJ2NARe7Ye5Bxeks5uancLgaJpZM4Wea_7&data=02%7C01%7C%7C92b1d1ba19eb43aac6b408d6198c06b6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636724486529011654&sdata=Q2Tg4Ef1%2FA2NOG9Rlg%2Bobz8yolHKI1PTaZX4TaczSa4%3D&reserved=0

.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/issues/42#issuecomment-421080320, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMv4721Y-KGX3IKrq_TVyUneV6-s6ks5uapB-gaJpZM4Wea_7 .

thiagolunardi commented 5 years ago

Ok, I was already using like that, but I was expecting something else. Anyhow, thanks for your time, and great job! I'm having a nice case of use here. If you someday be interested to know, just ping me. :+1: