-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
827 lines (569 loc) · 45.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
<!DOCTYPE html>
<html>
<head>
<meta name="generator" content="Hugo 0.91.2" />
<title>
Saji Weerasingham
</title>
</head>
<body>
<div class="h-feed">
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/27/and-its-hard-to-hold.html" class="u-url"><time class="dt-published" datetime="2025-02-27 05:58:23 +1000">Feb 27, 2025</time></a>
<div class="e-content">
<p>And it’s hard to hold a candle, in the cold Manchester rain #munips #mufc #manchesterunited</p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/25/make-your-own-mind-up.html" class="u-url"><time class="dt-published" datetime="2025-02-25 06:03:55 +1000">Feb 25, 2025</time></a>
<div class="e-content">
<p>Make your own mind up on the PM’s performance on #qanda #auspol</p>
<p><a href="https://www.youtube.com/live/mx8k9k83sWw?si=WDeJL9w48Vv_5DBG">www.youtube.com/live/mx8k…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/24/great-video-with-examples-that.html" class="u-url"><time class="dt-published" datetime="2025-02-24 12:25:58 +1000">Feb 24, 2025</time></a>
<div class="e-content">
<p>Great video, with examples, that explains how preferential voting works in #auspol</p>
<p><a href="https://youtu.be/YiLAx7kp4Rc?si=Oy0jLQMpZzB1mkwh">youtu.be/YiLAx7kp4…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/24/its-a-shame-to-see.html" class="u-url"><time class="dt-published" datetime="2025-02-24 09:53:07 +1000">Feb 24, 2025</time></a>
<div class="e-content">
<p>It’s a shame to see that our Matildas are just not in the same class as best national women’s teams, despite having a lot a players playing in the English WSL #matildas</p>
<p><!-- raw HTML omitted --><!-- raw HTML omitted --></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/22/maguire-ballwatching-on-that-second.html" class="u-url"><time class="dt-published" datetime="2025-02-22 23:37:47 +1000">Feb 22, 2025</time></a>
<div class="e-content">
<p>Maguire, ball-watching on that second goal, as usual.</p>
<p>He never scans! #manutd #manchesterunited</p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/22/elon-wont-be-able-to.html" class="u-url"><time class="dt-published" datetime="2025-02-22 17:07:52 +1000">Feb 22, 2025</time></a>
<div class="e-content">
<p>#elon won’t be able to cut $2 trillion from the US federal budget, here’s why: <a href="https://youtu.be/lG9pxvpGY-Q?si=vIefVZreW5mDAAvg">youtu.be/lG9pxvpGY…</a></p>
<p>#trump #politics</p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/22/nuclearfusion-reactor-run-for-minutes.html" class="u-url"><time class="dt-published" datetime="2025-02-22 15:44:04 +1000">Feb 22, 2025</time></a>
<div class="e-content">
<p>#nuclearfusion reactor run for 22 minutes in France #energytransition #netzero</p>
<p><a href="https://newatlas.com/energy/france-tokamak-cea-west-fusion-reactor-record-plasma-duration/">newatlas.com/energy/fr…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/22/toxic-culture-in-spanish-football.html" class="u-url"><time class="dt-published" datetime="2025-02-22 06:05:51 +1000">Feb 22, 2025</time></a>
<div class="e-content">
<p>Toxic culture in Spanish football as exposed by the Rubiales kiss #womensfootball</p>
<p><a href="https://youtu.be/nbLH9sXAGLE?si=tS1QYR2ncIwQmrWV">youtu.be/nbLH9sXAG…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/21/the-worlds-largest-electric-ferry.html" class="u-url"><time class="dt-published" datetime="2025-02-22 05:13:27 +1000">Feb 22, 2025</time></a>
<div class="e-content">
<p>The world’s largest electric ferry #renewableenergy</p>
<p><a href="https://youtu.be/4rR57tXdOHQ?si=UDzJPnLmhUPfEq6t">youtu.be/4rR57tXdO…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/21/dont-believe-everything-you-hear.html" class="u-url"><time class="dt-published" datetime="2025-02-21 12:46:44 +1000">Feb 21, 2025</time></a>
<div class="e-content">
<p>Don’t believe everything you hear about making the public service smaller and more efficient #auspol</p>
<p><a href="https://youtu.be/j2X7ICTqiOc?si=DFUxRS32oz5sMyhz">youtu.be/j2X7ICTqi…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/21/if-youre-a-windows-user.html" class="u-url"><time class="dt-published" datetime="2025-02-21 11:26:21 +1000">Feb 21, 2025</time></a>
<div class="e-content">
<p>If you’re a Windows user and wished File Explorer could do more, then check these out #windows #fileexplorer</p>
<p><a href="https://youtu.be/uDUQrC5YxT0?si=A8wzTheIsWVvFiP5">youtu.be/uDUQrC5Yx…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/21/great-chat-about-manchesterunited-especially.html" class="u-url"><time class="dt-published" datetime="2025-02-21 06:17:44 +1000">Feb 21, 2025</time></a>
<div class="e-content">
<p>Great chat about #manchesterunited especially Ten Hag’s man-management issues, the precarious financial position, where the #glazersout movement is, and how Sir Jim is going so far</p>
<p><a href="https://open.spotify.com/episode/4WYeg7duHhs515R30owBIQ?si=mpmxpkPIR1mz_F-Nb38h0g">open.spotify.com/episode/4…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/21/i-found-this-super-interesting.html" class="u-url"><time class="dt-published" datetime="2025-02-21 05:25:16 +1000">Feb 21, 2025</time></a>
<div class="e-content">
<p>I found this super interesting #football #footballanalytics #ai #bigdata</p>
<p><a href="https://open.spotify.com/episode/1c6H6gR5eB91Wg2YoGmaiM?si=wtBdDOt2SfeFpjU_LOBArA">open.spotify.com/episode/1…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/20/good-history-lesson-on-australian.html" class="u-url"><time class="dt-published" datetime="2025-02-20 16:02:50 +1000">Feb 20, 2025</time></a>
<div class="e-content">
<p>Good history lesson on Australian interest rates and why things are so expensive.</p>
<p>Spoiler, it’s not a domestic issue.</p>
<p>#auspol #costoflivingcrisis
<a href="https://open.spotify.com/episode/0a94fRXCVwYmxInr7iBlOW?si=a0OsrIdYSR6le93YnpJijw">open.spotify.com/episode/0…</a></p>
</div>
</div>
<div class="h-entry">
<a href="https://sajilicious.micro.blog/2025/02/16/informative-video-listing-the-events.html" class="u-url"><time class="dt-published" datetime="2025-02-16 06:34:33 +1000">Feb 16, 2025</time></a>
<div class="e-content">
<p>Informative video listing the events that shaped Trump’s idea to acquire Palestinian-occupied territories for American real estate developments #gaza #westbank</p>
<p><a href="https://youtu.be/DdUGdSEXkQU?si=lgPUu0tovHUPBdEs">youtu.be/DdUGdSEXk…</a></p>
</div>
</div>
<div class="h-entry">
<h1><a href="https://sajilicious.micro.blog/2025/02/15/domain-event-dispatching-using-the.html">Domain event dispatching using the outbox pattern with Entity Framework</a></h1>
<a href="https://sajilicious.micro.blog/2025/02/15/domain-event-dispatching-using-the.html" class="u-url"><time class="dt-published" datetime="2025-02-15 02:33:16 +1000">Feb 15, 2025</time></a>
<div class="e-content">
<h2 id="what-is-domain-event-dispatching">What is domain event dispatching?</h2>
<p>Domain event dispatching is a concept that related to <a href="https://martinfowler.com/bliki/DomainDrivenDesign.html">domain-driven design</a>, or DDD as it’s also known.</p>
<p>Having said that, event dispatching is central to any <a href="https://learn.microsoft.com/en-us/azure/architecture/guide/architecture-styles/event-driven">event-driven architecture</a>, which follows the <a href="https://learn.microsoft.com/en-us/azure/architecture/patterns/publisher-subscriber">publisher-subscriber pattern</a>.</p>
<p>Now, I’ve not actually read Eric Evans' seminal book on domain-driven design, <a href="https://www.amazon.com.au/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Domain-driven Design: Tackling Complexity in the Heart of Software</a>, so I’m unsure whether Evans suggests whether domain events should be published as part of the transaction that creates them, or have the event persisted with the change in application state and then later published using an <a href="https://codeopinion.com/outbox-pattern-reliably-save-state-publish-events">outbox pattern</a>.</p>
<p>I prefer the outbox pattern for domain event dispatching because I don’t think you want a scenario where data is persisted and an event is raised that has multiple subscribers, but one of the subscribers fails to execute, causing the whole transation to be rolled back.</p>
<p>You then get an inconsistent scenario where certain event handlers have been handled, but the data that relates to those actions does not exist. Why send a confirmation email for an account that wasn’t successfully regsitered.</p>
<p>Or, conversely, the transaction is not rolled back and one subscriber has failed to execute (including retries with back-off).</p>
<p>The outbox pattern, keeps a record of whether the event has been dispatched or “sent”, behaving a bit like a service bus.</p>
<p>In this blog post, I’m going to explore how an application using <a href="https://learn.microsoft.com/en-us/aspnet/entity-framework">Entity Framework</a> as an ORM can use an outbox pattern to publish domain events that are persisted with the application data.</p>
<p>The packages used will be Entity Framewok and I will leverage <code>INotification</code> in <a href="https://github.com/jbogard/MediatR">MediatR</a> to assist with the publisher-subscriber implementation.</p>
<p>All of these code samples are taken from my <a href="https://github.com/TheMagnificent11/lewee">Lewee</a> project.</p>
<h2 id="domain-event">Domain Event</h2>
<p>Here’s rough representation of a domain event.</p>
<p>I’ve included a <code>CorrelationId</code> property that I believe should be set to allow you to correlate the logs from the original transaction that persisted the <a href="https://martinfowler.com/bliki/DDD_Aggregate.html">aggregate root</a> and all the subsequent events that get handled as part of the dispatching.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> MediatR;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">interface</span> IDomainEvent : INotification
{
Guid CorrelationId { <span style="color:#66d9ef">get</span>; }
}
</code></pre></div><p>And here’s a sample implementation of an menu item being added to the table’s order at a restaurant.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">MenuItemAddedToOrderDomainEvent</span> : IDomainEvent
{
<span style="color:#66d9ef">public</span> MenuItemAddedToOrderDomainEvent(
Guid correlationId,
Guid tableId,
<span style="color:#66d9ef">int</span> tableNumber,
Guid orderId,
Guid menuItemId,
<span style="color:#66d9ef">decimal</span> price)
{
<span style="color:#66d9ef">this</span>.CorrelationId = correlationId;
<span style="color:#66d9ef">this</span>.TableId = tableId;
<span style="color:#66d9ef">this</span>.TableNumber = tableNumber;
<span style="color:#66d9ef">this</span>.OrderId = orderId;
<span style="color:#66d9ef">this</span>.MenuItemId = menuItemId;
<span style="color:#66d9ef">this</span>.Price = price;
}
<span style="color:#66d9ef">public</span> Guid CorrelationId { <span style="color:#66d9ef">get</span>; }
<span style="color:#66d9ef">public</span> Guid TableId { <span style="color:#66d9ef">get</span>; }
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">int</span> TableNumber { <span style="color:#66d9ef">get</span>; }
<span style="color:#66d9ef">public</span> Guid OrderId { <span style="color:#66d9ef">get</span>; }
<span style="color:#66d9ef">public</span> Guid MenuItemId { <span style="color:#66d9ef">get</span>; }
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">decimal</span> Price { <span style="color:#66d9ef">get</span>; }
}
</code></pre></div><h2 id="storing-domain-events">Storing Domain Events</h2>
<h3 id="entity-framework-entity">Entity Framework Entity</h3>
<p>Below is entity class used to store the details about a domain event after it related aggregate root has been persisted.</p>
<p>Things to note, we are storing the domain event as JSON (<code>DomainEventJson</code>) and also storing the assembly name (<code>DomainEventAssemblyName</code>) and class name (<code>DomainEventClassName</code>) to allow us to deserialize the JSON back to the doamin event in the <code>ToDomainEvent</code> method.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> System.Reflection;
<span style="color:#66d9ef">using</span> System.Text.Json;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DomainEventReference</span>
{
<span style="color:#66d9ef">public</span> DomainEventReference(DomainEvent domainEvent)
{
<span style="color:#66d9ef">this</span>.Id = Guid.NewGuid();
<span style="color:#66d9ef">this</span>.DomainEventAssemblyName = assemblyName;
<span style="color:#66d9ef">this</span>.DomainEventClassName = fullClassName;
<span style="color:#66d9ef">this</span>.DomainEventJson = JsonSerializer.Serialize(domainEvent, domainEventType);
<span style="color:#66d9ef">this</span>.PersistedAt = DateTime.UtcNow;
<span style="color:#66d9ef">this</span>.Dispatched = <span style="color:#66d9ef">false</span>;
}
<span style="color:#75715e">// EF constructor
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">private</span> DomainEventReference()
{
<span style="color:#66d9ef">this</span>.DomainEventAssemblyName = <span style="color:#66d9ef">string</span>.Empty;
<span style="color:#66d9ef">this</span>.DomainEventClassName = <span style="color:#66d9ef">string</span>.Empty;
<span style="color:#66d9ef">this</span>.DomainEventJson = <span style="color:#e6db74">"{}"</span>;
<span style="color:#66d9ef">this</span>.PersistedAt = DateTime.UtcNow;
<span style="color:#66d9ef">this</span>.Dispatched = <span style="color:#66d9ef">false</span>;
}
<span style="color:#66d9ef">public</span> Guid Id { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">string</span> DomainEventAssemblyName { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">string</span> DomainEventClassName { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">string</span> DomainEventJson { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">bool</span> Dispatched { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> DateTime PersistedAt { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> DateTime? DispatchedAt { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> DomainEvent? ToDomainEvent()
{
<span style="color:#66d9ef">if</span> (<span style="color:#66d9ef">string</span>.IsNullOrWhiteSpace(<span style="color:#66d9ef">this</span>.DomainEventJson))
{
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">null</span>;
}
<span style="color:#66d9ef">var</span> assembly = Assembly.Load(<span style="color:#66d9ef">this</span>.DomainEventAssemblyName);
<span style="color:#66d9ef">var</span> targetType = assembly.GetType(<span style="color:#66d9ef">this</span>.DomainEventClassName);
<span style="color:#66d9ef">if</span> (targetType == <span style="color:#66d9ef">null</span>)
{
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">null</span>;
}
<span style="color:#66d9ef">var</span> objDomainEvent = Deserialize(<span style="color:#66d9ef">this</span>.DomainEventJson, targetType);
<span style="color:#66d9ef">if</span> (objDomainEvent <span style="color:#66d9ef">is</span> not DomainEvent domainEvent)
{
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">null</span>;
}
domainEvent.UserId = <span style="color:#66d9ef">this</span>.UserId;
<span style="color:#66d9ef">return</span> domainEvent;
<span style="color:#66d9ef">static</span> <span style="color:#66d9ef">object?</span> Deserialize(<span style="color:#66d9ef">string</span> json, Type type)
{
<span style="color:#66d9ef">try</span>
{
<span style="color:#66d9ef">return</span> JsonSerializer.Deserialize(json, type);
}
<span style="color:#66d9ef">catch</span>
{
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">null</span>;
}
}
}
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> Dispatch()
{
<span style="color:#66d9ef">this</span>.Dispatched = <span style="color:#66d9ef">true</span>;
<span style="color:#66d9ef">this</span>.DispatchedAt = DateTime.UtcNow;
}
}
</code></pre></div><p>And here’s how we’ve configured the underlying database table.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore;
<span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore.Metadata.Builders;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DomainEventReferenceConfiguration</span> : IEntityTypeConfiguration<DomainEventReference>
{
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> Configure(EntityTypeBuilder<DomainEventReference> builder)
{
builder.HasKey(x => x.Id);
builder.Property(x => x.DomainEventAssemblyName)
.HasMaxLength(<span style="color:#ae81ff">255</span>)
.IsRequired();
builder.Property(x => x.DomainEventClassName)
.HasMaxLength(<span style="color:#ae81ff">255</span>)
.IsRequired();
builder.Property(x => x.DomainEventJson)
.HasMaxLength(<span style="color:#ae81ff">8000</span>)
.IsRequired();
builder.Property(x => x.Dispatched)
.IsRequired();
builder.Property(x => x.PersistedAt)
.IsRequired();
builder.Property(x => x.DispatchedAt)
.IsRequired(<span style="color:#66d9ef">false</span>);
builder.Property(x => x.UserId)
.HasMaxLength(<span style="color:#ae81ff">50</span>);
builder.HasIndex(
nameof(DomainEventReference.Dispatched),
nameof(DomainEventReference.PersistedAt));
}
}
</code></pre></div><h3 id="how-the-aggregate-root-stores-the-domain-event">How the aggregate root stores the domain event</h3>
<p>The aggregate root needs a collection of domain events on it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DomainEventsCollection</span>
{
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">readonly</span> List<DomainEvent> domainEvents = <span style="color:#66d9ef">new</span>();
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">readonly</span> <span style="color:#66d9ef">object</span> syncLock = <span style="color:#66d9ef">new</span>();
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> Raise<T>(T domainEvent)
<span style="color:#66d9ef">where</span> T : DomainEvent
{
<span style="color:#66d9ef">lock</span> (<span style="color:#66d9ef">this</span>.syncLock)
{
<span style="color:#66d9ef">this</span>.domainEvents.Add(domainEvent);
}
}
<span style="color:#66d9ef">public</span> DomainEvent[] GetAndClear()
{
<span style="color:#66d9ef">lock</span> (<span style="color:#66d9ef">this</span>.syncLock)
{
<span style="color:#66d9ef">var</span> events = <span style="color:#66d9ef">this</span>.domainEvents.ToArray();
<span style="color:#66d9ef">this</span>.domainEvents.Clear();
<span style="color:#66d9ef">return</span> events;
}
}
}
</code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">abstract</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">AggregateRoot</span> : Entity
{
<span style="color:#66d9ef">protected</span> AggregateRoot()
: <span style="color:#66d9ef">base</span>(Guid.NewGuid())
{
}
<span style="color:#66d9ef">protected</span> AggregateRoot(Guid id)
: <span style="color:#66d9ef">base</span>(id)
{
}
<span style="color:#66d9ef">public</span> DomainEventsCollection DomainEvents { <span style="color:#66d9ef">get</span>; } = <span style="color:#66d9ef">new</span> DomainEventsCollection();
}
</code></pre></div><p>And here’s a sample implementation of an aggregate root “raising” a domain event.</p>
<p>In this example, a menu item is being added to the order of a table at a restaurant.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Table</span> : AggregateRoot
{
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">readonly</span> List<Order> orders = <span style="color:#66d9ef">new</span>();
<span style="color:#66d9ef">public</span> Table(Guid id, <span style="color:#66d9ef">int</span> tableNumber)
: <span style="color:#66d9ef">base</span>(id)
{
<span style="color:#66d9ef">this</span>.TableNumber = tableNumber;
}
<span style="color:#66d9ef">public</span> Order? CurrentOrder => <span style="color:#66d9ef">this</span>.orders
.Where(x => x.OrderStatusId != OrderStatus.Paid)
.Where(x => !x.IsDeleted)
.OrderByDescending(x => x.CreatedAtUtc)
.FirstOrDefault();
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">int</span> TableNumber { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">bool</span> IsInUse { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">public</span> IReadOnlyCollection<Order> Orders => <span style="color:#66d9ef">this</span>.orders;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> OrderMenuItem(MenuItem menuItem, Guid correlationId)
{
<span style="color:#66d9ef">if</span> (!<span style="color:#66d9ef">this</span>.IsInUse || <span style="color:#66d9ef">this</span>.CurrentOrder == <span style="color:#66d9ef">null</span>)
{
<span style="color:#66d9ef">throw</span> <span style="color:#66d9ef">new</span> DomainException(ErrorMessages.CannotOrderIfTableNotInUse);
}
<span style="color:#66d9ef">this</span>.CurrentOrder.AddItem(menuItem);
<span style="color:#66d9ef">this</span>.DomainEvents.Raise(<span style="color:#66d9ef">new</span> MenuItemAddedToOrderDomainEvent(
correlationId,
<span style="color:#66d9ef">this</span>.Id,
<span style="color:#66d9ef">this</span>.TableNumber,
<span style="color:#66d9ef">this</span>.CurrentOrder.Id,
menuItem.Id,
menuItem.Price));
}
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">ErrorMessages</span>
{
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">string</span> CannotOrderIfTableNotInUse = <span style="color:#e6db74">"Cannot order items if table is not in use"</span>;
}
}
</code></pre></div><h3 id="how-the-dbcontext-stores-the-domain-event">How the DbContext stores the domain event</h3>
<p>We are going to use a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.diagnostics.savechangesinterceptor">SaveChangesInterceptor</a> to find the domain events added to our aggregate roots and add them as <code>DomainEventReference</code> instances before “save changes” executes.</p>
<p>To do that, we need to be able easily identify the <code>DbSet</code> for our <code>DomainEventReference</code> entities.</p>
<p>So, we’ve created an <code>IApplicationDbContext</code> interface that we can add to our Entity Framework <code>DbContext</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">interface</span> IApplicationDbContext
{
DbSet<DomainEventReference>? DomainEventReferences { <span style="color:#66d9ef">get</span>; }
}
</code></pre></div><p>And here’s the interceptor that find the domain events on the aggregate roots and stores them in the <code>DbContext</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore;
<span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore.ChangeTracking;
<span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore.Diagnostics;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DomainEventSaveChangesInterceptor</span><TContext> : SaveChangesInterceptor
<span style="color:#66d9ef">where</span> TContext : DbContext, IApplicationDbContext
{
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">override</span> InterceptionResult<<span style="color:#66d9ef">int</span>> SavingChanges(
DbContextEventData eventData,
InterceptionResult<<span style="color:#66d9ef">int</span>> result)
{
<span style="color:#66d9ef">this</span>.StoreDomainEvents(eventData.Context);
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">base</span>.SavingChanges(eventData, result);
}
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">override</span> ValueTask<InterceptionResult<<span style="color:#66d9ef">int</span>>> SavingChangesAsync(
DbContextEventData eventData,
InterceptionResult<<span style="color:#66d9ef">int</span>> result,
CancellationToken cancellationToken = <span style="color:#66d9ef">default</span>)
{
<span style="color:#66d9ef">this</span>.StoreDomainEvents(eventData.Context);
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">base</span>.SavingChangesAsync(eventData, result, cancellationToken);
}
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">void</span> StoreDomainEvents(DbContext? context)
{
<span style="color:#66d9ef">if</span> (context == <span style="color:#66d9ef">null</span> || context <span style="color:#66d9ef">is</span> not TContext)
{
<span style="color:#66d9ef">return</span>;
}
<span style="color:#66d9ef">foreach</span> (<span style="color:#66d9ef">var</span> entry <span style="color:#66d9ef">in</span> context.ChangeTracker.Entries().ToList())
{
<span style="color:#66d9ef">this</span>.StoreDomainEventsForEntry((TContext)context, entry);
}
}
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">void</span> StoreDomainEventsForEntry(TContext context, EntityEntry entry)
{
<span style="color:#66d9ef">if</span> (entry.Entity <span style="color:#66d9ef">is</span> not AggregateRoot aggregateRootEntity)
{
<span style="color:#66d9ef">return</span>;
}
<span style="color:#66d9ef">var</span> events = aggregateRootEntity.DomainEvents.GetAndClear();
<span style="color:#66d9ef">foreach</span> (<span style="color:#66d9ef">var</span> domainEvent <span style="color:#66d9ef">in</span> events)
{
<span style="color:#66d9ef">if</span> (domainEvent == <span style="color:#66d9ef">null</span>)
{
<span style="color:#66d9ef">continue</span>;
}
<span style="color:#66d9ef">var</span> reference = <span style="color:#66d9ef">new</span> DomainEventReference(domainEvent);
context.DomainEventReferences?.Add(reference);
}
}
}
</code></pre></div><p>Finally, here’s an abstract <code>DbContext</code> implementation that exposes the <code>DomainEventReference</code> <code>DbSet</code> and adds the <code>DomainEventSaveChangesInterceptor</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">abstract</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">ApplicationDbContext</span><TContext> : DbContext, IApplicationDbContext
<span style="color:#66d9ef">where</span> TContext : DbContext, IApplicationDbContext
{
<span style="color:#66d9ef">protected</span> ApplicationDbContext(DbContextOptions<TContext> options)
: <span style="color:#66d9ef">base</span>(options)
{
}
<span style="color:#66d9ef">public</span> DbSet<DomainEventReference>? DomainEventReferences { <span style="color:#66d9ef">get</span>; <span style="color:#66d9ef">internal</span> <span style="color:#66d9ef">set</span>; }
<span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">override</span> <span style="color:#66d9ef">void</span> OnModelCreating(ModelBuilder modelBuilder)
{
<span style="color:#66d9ef">base</span>.OnModelCreating(modelBuilder);
modelBuilder.ApplyConfiguration(<span style="color:#66d9ef">new</span> DomainEventReferenceConfiguration());
<span style="color:#66d9ef">this</span>.ConfigureDatabaseModel(modelBuilder);
}
<span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">override</span> <span style="color:#66d9ef">void</span> OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
<span style="color:#66d9ef">base</span>.OnConfiguring(optionsBuilder);
optionsBuilder.AddInterceptors(<span style="color:#66d9ef">new</span> DomainEventSaveChangesInterceptor<TContext>());
}
<span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">abstract</span> <span style="color:#66d9ef">void</span> ConfigureDatabaseModel(ModelBuilder modelBuilder);
}
</code></pre></div><h2 id="dispatching-domain-events">Dispatching Domain Events</h2>
<p>The code below reads from the database table for the <code>DomainEventReference</code> entity and dispatches them in batches of 50.</p>
<p>For event row, it deserializes the JSON to the original <code>IDomainEvent</code> and because <code>IDomainEvent</code> implements <code>INotification</code> from <code>MediatR</code>, you can use the <code>Publish</code> to achieve the publisher-subscriber pattern; there can be multiple notification handlers for each event. Conversely, if there are not notification handlers, <code>MediatR</code> will handle this for us and return successfully.</p>
<p>The domain event does not get marked as “dispatched” in the database unless all dispatching succeeds.</p>
<p>There is a downside here because you could have three notification handlers for an event, two could succeed and one could fail, causing the event does not get marked as dispatched.</p>
<p>Any process that tries to re-dispatch will attempt all three handlers again, so you could get duplication of certain handlers.</p>
<p>However, I think this is still better than the other scenario I outlined earlier.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> MediatR;
<span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore;
<span style="color:#66d9ef">using</span> Serilog;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DomainEventDispatcher</span><TContext>
<span style="color:#66d9ef">where</span> TContext : DbContext, IApplicationDbContext
{
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">int</span> BatchSize = <span style="color:#ae81ff">50</span>;
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">readonly</span> IDbContextFactory<TContext> dbContextFactory;
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">readonly</span> IMediator mediator;
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">readonly</span> ILogger logger;
<span style="color:#66d9ef">public</span> DomainEventDispatcher(
IDbContextFactory<TContext> dbContextFactory,
IMediator mediator,
ILogger logger)
{
<span style="color:#66d9ef">this</span>.dbContextFactory = dbContextFactory;
<span style="color:#66d9ef">this</span>.mediator = mediator;
<span style="color:#66d9ef">this</span>.logger = logger.ForContext<DomainEventDispatcher<TContext>>();
}
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">async</span> Task DispatchEvents(CancellationToken cancellationToken)
{
<span style="color:#66d9ef">var</span> eventsToDispatch = <span style="color:#66d9ef">await</span> <span style="color:#66d9ef">this</span>.ThereAreEventsToDispatch(cancellationToken);
<span style="color:#66d9ef">while</span> (eventsToDispatch && !cancellationToken.IsCancellationRequested)
{
<span style="color:#66d9ef">await</span> <span style="color:#66d9ef">this</span>.DispatchBatch(cancellationToken);
eventsToDispatch = <span style="color:#66d9ef">await</span> <span style="color:#66d9ef">this</span>.ThereAreEventsToDispatch(cancellationToken);
}
}
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">async</span> Task<<span style="color:#66d9ef">bool</span>> ThereAreEventsToDispatch(CancellationToken token)
{
<span style="color:#66d9ef">using</span> (<span style="color:#66d9ef">var</span> scope = <span style="color:#66d9ef">this</span>.dbContextFactory.CreateDbContext())
{
<span style="color:#66d9ef">var</span> dbSet = scope.Set<DomainEventReference>();
<span style="color:#66d9ef">if</span> (dbSet == <span style="color:#66d9ef">null</span>)
{
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">false</span>;
}
<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">await</span> dbSet
.Where(x => !x.Dispatched)
.OrderBy(x => x.PersistedAt)
.AnyAsync(token);
}
}
<span style="color:#66d9ef">private</span> <span style="color:#66d9ef">async</span> Task DispatchBatch(CancellationToken token)
{
<span style="color:#66d9ef">using</span> (<span style="color:#66d9ef">var</span> scope = <span style="color:#66d9ef">this</span>.dbContextFactory.CreateDbContext())
{
<span style="color:#66d9ef">var</span> dbSet = scope.Set<DomainEventReference>();
<span style="color:#66d9ef">if</span> (dbSet == <span style="color:#66d9ef">null</span>)
{
<span style="color:#66d9ef">return</span>;
}
<span style="color:#66d9ef">var</span> events = <span style="color:#66d9ef">await</span> dbSet
.Where(x => !x.Dispatched)
.OrderBy(x => x.PersistedAt)
.Take(BatchSize)
.ToArrayAsync(token);
<span style="color:#66d9ef">var</span> domainEvents = <span style="color:#66d9ef">new</span> List<DomainEvent>();
<span style="color:#66d9ef">foreach</span> (<span style="color:#66d9ef">var</span> domainEventReference <span style="color:#66d9ef">in</span> events)
{
domainEventReference.Dispatch();
<span style="color:#66d9ef">var</span> domainEvent = domainEventReference.ToDomainEvent();
<span style="color:#66d9ef">if</span> (domainEvent == <span style="color:#66d9ef">null</span>)
{
<span style="color:#66d9ef">this</span>.logger.Warning(
<span style="color:#e6db74">"Could not deserialize DomainEventReference {Id}"</span>,
domainEventReference.Id);
}
<span style="color:#66d9ef">else</span>
{
domainEvents.Add(domainEvent);
}
}
<span style="color:#66d9ef">if</span> (domainEvents.Any())
{
<span style="color:#66d9ef">foreach</span> (<span style="color:#66d9ef">var</span> domainEvent <span style="color:#66d9ef">in</span> domainEvents)
{
<span style="color:#66d9ef">await</span> <span style="color:#66d9ef">this</span>.mediator.Publish(domainEvent, token);
}
}
<span style="color:#66d9ef">await</span> scope.SaveChangesAsync(token);
}
}
}
</code></pre></div><p>So the code above does the dispatching, but what triggers the dispatching?</p>
<p>As far as I know, there is nothing similar to the <code>SaveChangesInterceptor</code> that executes after a successful save changes.</p>
<p>So, we’ve decided to use a background service.</p>
<p>In the code below, we are expecting our <code>DomainEventDispatcher</code> to dispatch events every 2.5 seconds.</p>
<p>So, any events that failed to dispatch will be retried after 2.5 seconds.</p>
<p><code>DomainEventReference</code> does not currently have a “retry count” or a “failed” property and that is definitely an improvement that could be added; fail if retried 10 times.</p>
<p>Under this solution, we will keep retrying and failed events will be attempted before new events, potentially causing a performance issue if failed events build up.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore;
<span style="color:#66d9ef">using</span> Microsoft.Extensions.Hosting;
<span style="color:#66d9ef">namespace</span> Lewee.Infrastructure.Data;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DomainEventDispatcherService</span><TContext> : BackgroundService
<span style="color:#66d9ef">where</span> TContext : DbContext, IApplicationDbContext
{
<span style="color:#66d9ef">public</span> DomainEventDispatcherService(DomainEventDispatcher<TContext> domainEventDispatcher)
{
<span style="color:#66d9ef">this</span>.DomainEventDispatcher = domainEventDispatcher;
}
<span style="color:#66d9ef">public</span> DomainEventDispatcher<TContext> DomainEventDispatcher { <span style="color:#66d9ef">get</span>; }
<span style="color:#66d9ef">protected</span> <span style="color:#66d9ef">override</span> <span style="color:#66d9ef">async</span> Task ExecuteAsync(CancellationToken stoppingToken)
{
<span style="color:#66d9ef">while</span> (!stoppingToken.IsCancellationRequested)
{
<span style="color:#66d9ef">await</span> <span style="color:#66d9ef">this</span>.DomainEventDispatcher.DispatchEvents(stoppingToken);
<span style="color:#66d9ef">await</span> Task.Delay(<span style="color:#ae81ff">2500</span>, stoppingToken);
}
}
}
</code></pre></div><p>There are definitely better ways to achieve this.</p>
<p>You could override save changes on your <code>DbContext</code> to trigger your domain event dispatcher and later you use some sort of retry policy if any events fails to dispatch.</p>
<p>That would be more efficient, but more complicated and harder to implement.</p>
<h2 id="dependency-injection-configuration">Dependency Injection Configuration</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cs" data-lang="cs"><span style="color:#66d9ef">using</span> Microsoft.EntityFrameworkCore;
<span style="color:#66d9ef">using</span> Microsoft.Extensions.DependencyInjection;
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">ApplicationDbContextServiceCollectionExtensions</span>
{
<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">static</span> IServiceCollection ConfigureDatabase<T>(
<span style="color:#66d9ef">this</span> IServiceCollection services,
<span style="color:#66d9ef">string</span> connectionString)
<span style="color:#66d9ef">where</span> T : ApplicationDbContext<T>
{
services.AddDbContextFactory<T>(options => options.UseSqlServer(connectionString));
services.AddScoped<T>();
services.AddSingleton<DomainEventDispatcher<T>>();
services.AddHostedService<DomainEventDispatcherService<T>>();
<span style="color:#66d9ef">return</span> services;
}
}
</code></pre></div><h2 id="this-is-a-lot-of-boilerplate">This is a lot of boilerplate</h2>
<p>This seems like a lot of code to achieve what I’d expect to be relatively straight-forward.</p>
<p>Given this is fairly common pattern and that DDD is used by a lot in software development, you’d expect that there are frameworks that do this for you.</p>
<p>That’s what I’ve tried to achieve with <a href="https://github.com/TheMagnificent11/lewee">Lewee</a>.</p>
<p>However, there’s definitely a better way.</p>
<p>In a future blog post, I’d like to explore how to dispatch to a message broker, probably <code>RabbitMQ</code> via <a href="https://masstransit.io">MassTransit</a>, instead of using <code>Mediatr</code> notifications. I feel like this is more flexible as any service within your distributed application can handle your domain events. not just the service that dispatches it.</p>
</div>
</div>
</div>
</body>
</html>