No video

The 2 MediatR features people don't know about but should

  Рет қаралды 34,779

Nick Chapsas

Nick Chapsas

Күн бұрын

Пікірлер: 81
@user-nq8ln7ps7x
@user-nq8ln7ps7x 2 жыл бұрын
Default sequential execution of notification handlers makes it use really simple for implementing an domain events bus with transactions support. With parallel execution (that you can implement with custom publish strategy), in case of domain event bus, it will require additional scopes for each handler and most likely some retries, so it be not that easy to implement and execution most likely will be fully asynchronous - without possibility to await completion of event execution (because of long retries)
@acidrazor
@acidrazor 2 жыл бұрын
Would love to see the streaming capabilities linked up to a JS frontend updating a store or a table or something
@brianm1864
@brianm1864 2 жыл бұрын
That's cool that MediatR added the streaming! I've been using IAsyncEnumerable (without MediattR) to stream large response sets back to the front-end in Blazor for a while now. Works great.
@carstenberggreen7509
@carstenberggreen7509 2 жыл бұрын
Been using Notification for more than a year. Its a great way to "simulate" internal Domain Events in your applications where different parts of the applications wants to know about this or having multiple integrations listening for events using the same interface.
@abhinavkapoor321
@abhinavkapoor321 3 ай бұрын
exactly!! thats a great usecase and its possible to rollback the cause if the effect has not been applied.
@tofu1687
@tofu1687 2 жыл бұрын
In my opinion, this video is the best of all - but maybe it's because it fits perfectly with solving a problem that came up 4 hours ago at work - it's like you made it for ME. Now I'm sad because, even though I know I'm biased, I'll never be able to feel such bliss watching your videos again.
@prom3theu581
@prom3theu581 2 жыл бұрын
You can actully write a custom execution strategy for notifications, which allow execution in parallel
@fifty6737
@fifty6737 2 жыл бұрын
months ago i didn't know shit about CQRS, i spent the last weeks trying MediatR and it's very fucking powerful, and now streaming capabilities
@tera.
@tera. 2 жыл бұрын
Why don't you use records more often in your videos? You often create classes with a ctor and get only properties, but records remove all that boilerplate.
@nickchapsas
@nickchapsas 2 жыл бұрын
Because records don’t play nice with several packages and I don’t wanna point people to potentially something that won’t work.
@tera.
@tera. 2 жыл бұрын
@@nickchapsas Understandable, though I haven't come across any issues myself and I use them wherever appropriate.
@homeropata
@homeropata 2 жыл бұрын
Great video thanks. I didn't know the streaming support. As for the Publish, I knew it and used it. In my case, I put side operations into the handlers that are written later. In these handlers, these were put into a background job queue so it doesn't hurt the performance or stability of the main operation.
@PelFox
@PelFox 2 жыл бұрын
Great video! What's the actual use case of IAsyncEnumerable and when would you use it compared to maybe SignalR?
@CesarDemi81
@CesarDemi81 2 жыл бұрын
Sequential execution of the notification handlers is useful when using INotification as domain events and you're using things like EF that are not thread-safe, so it really works well for those cases... But yeah, it should be some optionally configurable thing in the library...
@dayv2005
@dayv2005 Жыл бұрын
I really like the notifications aspect of it. Jason Taylor uses this pretty extensively in his clean architecture template.
@codewkarim
@codewkarim 2 жыл бұрын
Wouh, the streaming!! I knew about the notification but not of the fact that it's sequential :o! Thanks NICK!
@marcusmajarra
@marcusmajarra 2 жыл бұрын
Multi-casting notifications is pretty much fundamental to an event sourcing + CQRS architecture. I've done this long before MediatR was a thing, but it's always nice to have a framework that does this out of the box.
@thomai5287
@thomai5287 2 жыл бұрын
I once asked the MediatR guys why they used sequential execution as default. The answer was, that mostly there's something like EFCore involved in most projects which is not threadsafe. Makes sense to me.
@nickchapsas
@nickchapsas 2 жыл бұрын
Which is such a bad reason
@pablocom
@pablocom 2 жыл бұрын
Looking forward to the IAsyncEnumerable video ;)
@ChristopherHaws90
@ChristopherHaws90 Жыл бұрын
I use record types for my requests and notifications. It is much cleaner :) Also, I use notifications in our app. If Jimmy changed the behavior to run them in parallel it would break our app. The reason for that decision is because you are not supposed to spawn multiple threads in a web request. Lots of libraries will break if you try to, for example EF Core. I agree that it would be nice if there were a new mechanism added that supported this for when you are wanting to use mediatr outside of a web scenario. Each notification handler would need to run within it's own lifetime scope and be treated as a separate unit of work though.
@chris-pee
@chris-pee Жыл бұрын
You're mixing up the concepts of parallelism and concurency, and you're wrong. Executing handlers at the concurrently doesn't mean spawning multiple threads (you could do that but it would be a classic mistake). For example refer to Task.WhenAll, which doesn't spawn threads. The EF Core use case has nothing to do with parallelism as well - DbContext just doesn't support concurrency and throws. There is a way around that btw, which would be injecting a factory.
@nove1398
@nove1398 2 жыл бұрын
Way to go. Thanks for bringing these scenarios to light and the gotcha's associated
@steve-wright-uk
@steve-wright-uk 2 жыл бұрын
Looking forward to your IAsyncEnumerable video
@kondziossj3
@kondziossj3 2 жыл бұрын
8:10 mostly because of thinks like Entity Framework, what not allow multiple request at the same time, and that's if you know that you can override publisher method to run as you want
@nickchapsas
@nickchapsas 2 жыл бұрын
EF supported multithreaded contexts
@kondziossj3
@kondziossj3 2 жыл бұрын
@@nickchapsas As default? I dont think But always we could use trancient scope or other solutions But each of method have some disadvantages For the same reason MediatR use method that have the lowest probability to get some 'strange error'
@paulkoopmans4620
@paulkoopmans4620 2 жыл бұрын
​@@nickchapsas As far as I know and understand from the MS documentation it is indeed not safe and have to agree with KondzioSSJ4. this must probably my 20th time trying to comment so I am not adding any links etc.
@andreast.1373
@andreast.1373 2 жыл бұрын
That's really cool! I can see some use cases for the notification feature, if there is a specific order on how they are sent but I doubt that is the case. Awesome content as always, keep it up! :)
@KonstantinKuda
@KonstantinKuda 2 жыл бұрын
Great video. Thanks!
@ilyakurmaz
@ilyakurmaz 2 жыл бұрын
Thanks for the great video, Nick! I've tried the notification feature for Domain Events recently and it worked great (however it was a relatively small use-case). What are your concerns about it or maybe alternatives?
@DerekWelton
@DerekWelton 2 жыл бұрын
I'm interested in the concerns and alternatives as well
@antonmartyniuk
@antonmartyniuk 2 жыл бұрын
Streams is a really coo feature. I am using Notifications sometimes but I often fire and forget them so they are like events. I just use _ = mediator.Publish(...); and not await them
@cwq704
@cwq704 2 жыл бұрын
I had also used it in the same way. Just that would need create scope and service explicitly in the handlers to avoid context has been destroyed situation. Not sure if any drawbacks though
@alexanderbadewitz1288
@alexanderbadewitz1288 2 жыл бұрын
Great Video. Thank you Nick for your permanent great work 👍 Always up to date and interesting
@branislavpetrovic7486
@branislavpetrovic7486 2 жыл бұрын
Great video! I pretty like streaming capability of MediatR. Thanks!
@mustafizurrohman88
@mustafizurrohman88 2 жыл бұрын
Awesome content! Thanks .. Cant wait to see your video on IAsyncEnumerable .. Could you please explain how EF Core works with IAsyncEnumerable? Thanks
@pdevito
@pdevito 2 жыл бұрын
The quick note at the end about alts for notifications being better was interesting. Do you mean something like MassTransit’s in memory mediator? What gaps to you the the MediatR package has
@lucademarco5969
@lucademarco5969 2 жыл бұрын
I suppose you should not even wait for the notifications to be published... Once you send them is someone ekse responsibility to do something with them, it should be a fire and forfet thing... therefore removing the await will save you from waiting 5 seconds. Or is there a reason to await it? Thanks in advance
@carl-henrikkristoffersen2313
@carl-henrikkristoffersen2313 2 жыл бұрын
How does this compare to SignalR in terms of use cases? I've previously implemented SignalR for sending event-driven messages and updates to a web application. As I've understood it, MediatR notification support is useful when clients are polling for updates, while SignalR is useful for pushing updates out to subscribing clients - do you agree?
@krccmsitp2884
@krccmsitp2884 2 жыл бұрын
SignalR is for web apps, MediatR is "backend-only" and in-process messaging.
@SibTiger33
@SibTiger33 Жыл бұрын
Notifications can run in parallel in latest version of mediatr 🎉🎉🎉
@iliqngorki3310
@iliqngorki3310 Жыл бұрын
Can you made a video how to handle Stream on some Front End technology ? Thank you for the great video's.
@AhmedMohammed23
@AhmedMohammed23 5 ай бұрын
is there a way to excute notifications in the background as a background job or something and not wait on it?!
@blackbird700
@blackbird700 2 жыл бұрын
we use notifications for publishing messages to rabbitmq (eg same notification from various parts of service)
@TheAzerue
@TheAzerue 2 жыл бұрын
Hi @Nick This is a little off topic question. I saw yout fast-endpoints video and this. Do you think it makes to sense to use fast-endpoint with MediatR or it will be over engineering.
@techman6713
@techman6713 2 жыл бұрын
Thanks for video! I have a question: if I want to subscribe a notification from front - end, should I make a request and then, wait for response?
@NiamorH
@NiamorH 2 жыл бұрын
I prefer ReactiveExtensions to send 'notifications'. I can subscribe on separate threads, etc.
@techbuterbrod
@techbuterbrod 2 жыл бұрын
Hi, Nick! Thx for your video. What do you think about Masstransit? And what do you think about use Masstransit like a Message and Consumers pattern thithout MediatR?
@MXDMND_
@MXDMND_ 2 жыл бұрын
Nick, can you recommend a better alternative for the mediators notification feature? Thank you
@expertreviews1112
@expertreviews1112 2 жыл бұрын
Very nice vid… how do you find out if a feature is being used or not? Is there a way to search people’s repositories on git??
@SibTiger33
@SibTiger33 Жыл бұрын
A shame u can't run notifications in another thread. For my use case I generally use notifications to abstract event sending to a queue and then implement real work. Sadly u can't do any long running or real work with notifications (I. E sending emails, or some image manipulation due to the delay) so I have a handler to send to a queue and then do real work in whatever listens to messages in the queue. Not ideal but works nicely for my needs. I've also used notifications for domain events.
@camoman1000
@camoman1000 2 жыл бұрын
Does mediatr support observables in system.reactive?
@fifty6737
@fifty6737 2 жыл бұрын
Hey Nick do you have any idea how to accomplish MediatR + Redis + MongoDB with filtering, search & pagination, since redis only support querying by IDs, is there any way to do this elegantly
@camoman1000
@camoman1000 2 жыл бұрын
System.Reactive with observable could possibly be a super elegant solution here.
@ZhenyaKolobov
@ZhenyaKolobov 2 жыл бұрын
running handlers in parallel is not always a good idea. often they contain a call to the database, and this leads to errors, because DbContext is not thread safe
@nickchapsas
@nickchapsas 2 жыл бұрын
DbContext can be parallelised. Hamstringing your design because of poor db sdk features is bad
@alexisfibonacci
@alexisfibonacci 2 жыл бұрын
Why do you have to await the Notification? Why not just fire and forget?
@pilotboba
@pilotboba 2 жыл бұрын
Will that keep the request thread from returning to the pool?
@chrislamont7529
@chrislamont7529 2 жыл бұрын
You had me excited until the non parallel notifications.
@speakoutloud7293
@speakoutloud7293 2 жыл бұрын
Please Nick, don't name your videos like news articles! You are better than that! Name it as it should for a better understanding and not being like click baits.
@nickchapsas
@nickchapsas 2 жыл бұрын
I am really not better than that. Videos unfortunately need to be named like that to get the appropriate click through. This is how the game is played
@codeforme8860
@codeforme8860 2 жыл бұрын
I love notifications
@spacerecluse
@spacerecluse Жыл бұрын
-20? the people live at -58 in my country ))), I lived where +58 for a whole month
@amirhosseinahmadi3706
@amirhosseinahmadi3706 2 жыл бұрын
MeditatR is the greatest abomination the world has ever seen, every time I see a video being made on it, I die a little bit inside...
@paulkoopmans4620
@paulkoopmans4620 2 жыл бұрын
Don't like wine? don't drink it! Don't like cheese? don't eat it! If you don't like it... then f-ing don't watch. Obviously 74 million downloads, infers that quite a bit of people do like it and they have their personal reasons for it.
@nanvlad
@nanvlad 2 жыл бұрын
@@paulkoopmans4620 It's not a good analogy. If I don't like wine and like beer - I choose what I want. But if I'm in a company which drinks wine only I can't drink beer - I just need to find a new company. And the more popular wine is - the more companies drink it, more wine is produced to the market whereas beer marketing becomes less and less. And eventually I'm forced to drink wine like others or be alone (or with others who don't like wine).
@spirits_
@spirits_ 2 жыл бұрын
@@paulkoopmans4620 Are you copy pasting your response to everyone who has a different opinion on mediatr than you?
@SvMsk
@SvMsk 2 жыл бұрын
@@paulkoopmans4620 your response is as shallow as the original message, neither of you are posting any actual arguments for/against MediatR
@paulkoopmans4620
@paulkoopmans4620 2 жыл бұрын
​ @kalistrat It's ok that you don't like the analogy but what you are picking up from it is exactly what I meant; so in that sense it's good with me. I was exactly trying to convey that message. I am not here to convince then to use it. If they don't like it it is fine by me. To attack Nick that he should not pay attention to it is what I have problems with. He clearly likes it, which is why he makes the videos about it. He is giving his arguments and perspectives. Like other people commenting on other videos like .. I wish I could use .net6 I am stuck with 4.8. Really there is only one person you can "blame" for your personal professional development; and it's you. If you are working in a company where you are stuck on old tech or where they are using stuff you don't like... move on. I am sure one could find a company with peers that think alike.
@smiffy68
@smiffy68 2 жыл бұрын
Are mediatr passing you to promote their garbage? You're doing your community a disservice by promoting it at every turn. Just stop.
@paulkoopmans4620
@paulkoopmans4620 2 жыл бұрын
Don't like wine? don't drink it! Don't like cheese? don't eat it! If you don't like it... then f-ing don't watch. Obviously 74 million downloads, infers that quite a bit of people do like it and they have their personal reasons for it.
@spirits_
@spirits_ 2 жыл бұрын
@@paulkoopmans4620 Yes, it's quite overused and have ruined many a codebase.
@paulkoopmans4620
@paulkoopmans4620 2 жыл бұрын
@@spirits_ OK. Look... I appreciate your view. I can see that you might have seen usages of MediatR that have ruined several codebases. That does not take away the fact that many other might have opposite experiences. Nick has been open and honest when he had sponsored content. Based on that I think it is not a question whether or not he gets paid for promoting MediatR. That leaves us with one of two options. He either likes it or personally has no strong opinion on MediatR but recognizes that likely a big portion of his viewers do care about it and he wants to make content for them. Nick is not able to please every viewer. There has been videos in the past that I do not necessarily agree with him. I will, in those cases, never put any of these derogatory comments. His channel, his choices, his content. If one adds a good comment with a legit question about speed or something or you can share actual links or something that helps us all... that is what we are looking for.
@AJax2012
@AJax2012 2 жыл бұрын
@@spirits_ You can literally say this about any technology though - the thing that ruins codebases is rarely the technology itself, but rather how it is used by the developers. I could say the same thing about React, Java, or SQL (or even C#, to be frank) because I've seen extremely poor implementations of each, but that doesn't mean that any of those tools is inherently bad or shouldn't be discussed. Just that the group of people who worked on that code base didn't know how to use the tool properly.
@muhamedkarajic
@muhamedkarajic 2 жыл бұрын
@@AJax2012 nailed it.
How slow is MediatR really?
15:51
Nick Chapsas
Рет қаралды 60 М.
The fastest way to cast objects in C# is not so obvious
11:10
Nick Chapsas
Рет қаралды 73 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН
Oh No! My Doll Fell In The Dirt🤧💩
00:17
ToolTastic
Рет қаралды 11 МЛН
Matching Picture Challenge with Alfredo Larin's family! 👍
00:37
BigSchool
Рет қаралды 48 МЛН
娜美这是在浪费食物 #路飞#海贼王
00:20
路飞与唐舞桐
Рет қаралды 6 МЛН
3 .NET "Best Practices" I Changed My Mind About
10:16
Nick Chapsas
Рет қаралды 102 М.
The CORRECT way to implement Retries in .NET
17:01
Nick Chapsas
Рет қаралды 87 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 257 М.
5 Amazing Use Cases for MediatR Pipelines - Cross-Cutting Concerns
12:20
Milan Jovanović
Рет қаралды 11 М.
Why all your classes should be sealed by default in C#
11:43
Nick Chapsas
Рет қаралды 92 М.
The fastest way to iterate a List in C# is NOT what you think
13:42
Nick Chapsas
Рет қаралды 156 М.
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 143 М.
You DON'T want an In-Memory Event Bus like MediatR
11:20
CodeOpinion
Рет қаралды 22 М.
Stop using async void in C#! Do this instead.
13:12
Nick Chapsas
Рет қаралды 57 М.
Clean Message Bus Consumers with MediatR in .NET
27:20
Nick Chapsas
Рет қаралды 50 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН