Skip to content

Commit

Permalink
Dev (#118)
Browse files Browse the repository at this point in the history
* EventRouter Updates

* Updated dependencies to latest and fixed MassTransit example.

* Updated MassTransit test projects.

* Promoted EventHandling assembly to RCommon.Core as it is becoming more essential to have loosely coupled events locally in RCommon as well as in dependencies!

* Removed deprecated project.

* Feature/v2 unit testing (#114)

* Changing strategy for entity event tracking.

* Removed old icon. Updated EventRouter to allow for parameterized events to be passed in but also stored like a repository.

* Updated entity event tracking to enforce better async capabilities. Version bump.

* Feature/mediator enhancements (#117)

* Removed unneeded samples/files. Renamed existing examples.

* Removed DistributedUnitOfWorkBehavior as it is no longer neccesary. The IEntityEventTracker leverages IEventRouter to emit transactional events so we don't need to emit from UoW.

* Refactored MediatRNotificationHandler so that events no longer need to implement INotification - only ISerializable which is generic across mulitple types of eventing libraries.

* Added ability to send through mediator rather than just publish.

* Added Mediator abstraction with MediatR implementation.

* Simplified MediatR config.

* Added MediatR Request/Notification handling and refactored event handling.

* Added Mediator Request with response for MediatR implementation.

* Version bump.

Co-authored-by: Jason Webb <jason.webb@leadventure.com>
  • Loading branch information
JasonMWebb and jasonmwebb-lv authored Apr 1, 2024
1 parent ea2cee6 commit b1a17be
Show file tree
Hide file tree
Showing 101 changed files with 901 additions and 930 deletions.
7 changes: 6 additions & 1 deletion Examples/CleanWithCQRS/HR.LeaveManagement.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.EntityFrameworkCore;
using System.Transactions;
using RCommon.Persistence.Transactions;
using RCommon.Mediator.MediatR;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -30,7 +31,11 @@
})
.WithDateTimeSystem(dateTime => dateTime.Kind = DateTimeKind.Utc)
.WithSequentialGuidGenerator(guid => guid.DefaultSequentialGuidType = SequentialGuidType.SequentialAsString)
.AddUnitOfWorkToMediatorPipeline()
.WithMediator<MediatRBuilder>(mediator =>
{
mediator.AddLoggingToRequestPipeline();
mediator.AddUnitOfWorkToRequestPipeline();
})
.WithPersistence<EFCorePerisistenceBuilder, DefaultUnitOfWorkBuilder>(ef => // Repository/ORM configuration. We could easily swap out to NHibernate without impact to domain service up through the stack
{
// Add all the DbContexts here
Expand Down
16 changes: 6 additions & 10 deletions Examples/EventHandling/Examples.EventHandling.MediatR/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.EventHandling;
using RCommon.EventHandling.Producers;
using RCommon.Mediator;
using RCommon.Mediator.MediatR;
using RCommon.Mediator.Producers;
using RCommon.MediatR;
using RCommon.MediatR.Producers;
using System.Diagnostics;
using System.Reflection;
using static System.Net.Mime.MediaTypeNames;

try
{
Expand All @@ -27,16 +26,13 @@
{
// Configure RCommon
services.AddRCommon()
.WithEventHandling<InMemoryEventBusBuilder>(eventHandling =>
.WithEventHandling<MediatREventHandlingBuilder>(eventHandling =>
{
eventHandling.AddProducer<PublishWithMediatorEventProducer>();
eventHandling.AddProducer<PublishWithMediatREventProducer>();

eventHandling.AddSubscriber<TestEvent, TestEventHandler>();
//services.AddTransient<IAppNotificationHandler<TestEvent>, TestEventHandler>();
});

Console.WriteLine($"Total Services Registered:");
Console.WriteLine(services.GenerateServiceDescriptorsString());

}).Build();

Console.WriteLine("Example Starting");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using RCommon.EventHandling;
using MediatR;
using RCommon.EventHandling;
using RCommon.Mediator;
using RCommon.Mediator.Subscribers;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using RCommon;
using RCommon.EventHandling.Subscribers;
using RCommon.Mediator;
using System;
Expand All @@ -14,13 +15,12 @@ public class TestEventHandler : ISubscriber<TestEvent>
{
public TestEventHandler()
{

}


public async Task HandleAsync(TestEvent notification, CancellationToken cancellationToken = default)
{
Console.WriteLine("I just handled this event {0}", new object[] { notification.ToString() });
Console.WriteLine("{0} just handled this event {1}", new object[] { this.GetGenericTypeName(), notification });
await Task.CompletedTask;
}
}
Expand Down

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions Examples/EventSourcing/Samples.EventSourcing.EventFlow/MyId.cs

This file was deleted.

21 changes: 0 additions & 21 deletions Examples/EventSourcing/Samples.EventSourcing.EventFlow/MyState.cs

This file was deleted.

This file was deleted.

This file was deleted.

45 changes: 26 additions & 19 deletions Examples/Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RCommon.Mediator.MediatR.Te
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Messaging", "Messaging", "{35AE0870-0A6D-4F27-B534-B8DCDFD11A36}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Messaging.MassTransit", "Messaging\Samples.Messaging.MassTransitRabbitMq\Examples.Messaging.MassTransit.csproj", "{FC74E2FD-5B2D-4301-ABB7-838F458ED50D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Messaging.Wolverine", "Messaging\Samples.Messaging.WolverineRabbitMq\Examples.Messaging.Wolverine.csproj", "{B792333E-245B-48F0-A88E-F36EEF1F7C11}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Providers", "Providers", "{3199F749-0082-41D0-91D3-ECED117F8B08}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RCommon.DotNet6.Tests", "..\Tests\RCommon.DotNet6.Tests\RCommon.DotNet6.Tests.csproj", "{B93C2373-7ADD-4D1F-B8CB-8FF32EAF364E}"
Expand All @@ -109,12 +105,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.EventHandling.Medi
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CQRS", "CQRS", "{783F8A99-F164-42E3-BD7C-09D432D02DEE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Experimental", "Experimental", "{6509FEEC-F46C-4B03-82D4-8F2D78896160}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.EventHandling.InMemoryEventBus", "EventHandling\Examples.EventHandling.InMemoryEventBus\Examples.EventHandling.InMemoryEventBus.csproj", "{86CE6DBE-418E-440B-9C27-58B00AFB2FCA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.ApplicationServices.CQRS", "ApplicationServices\Examples.ApplicationServices.CQRS\Examples.ApplicationServices.CQRS.csproj", "{CEAA39C2-249C-44D0-94CF-8342CB35811D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Messaging.MassTransit", "Messaging\Examples.Messaging.MassTransit\Examples.Messaging.MassTransit.csproj", "{A7C5D513-08D7-4BBF-9CB9-307EE91DA81D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Messaging.Wolverine", "Messaging\Examples.Messaging.Wolverine\Examples.Messaging.Wolverine.csproj", "{06FE76EC-C7D1-4C46-8047-22D58C8437A2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Mediator.MediatR", "Mediator\Examples.Mediator.MediatR\Examples.Mediator.MediatR.csproj", "{05B6EF05-8053-45D1-8649-1779B0D7D6C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mediator", "Mediator", "{9085B4F5-E26A-471D-B25D-5D69B0337B02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -261,14 +263,6 @@ Global
{38508541-4429-4A30-9D84-B151250E08B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38508541-4429-4A30-9D84-B151250E08B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38508541-4429-4A30-9D84-B151250E08B8}.Release|Any CPU.Build.0 = Release|Any CPU
{FC74E2FD-5B2D-4301-ABB7-838F458ED50D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC74E2FD-5B2D-4301-ABB7-838F458ED50D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC74E2FD-5B2D-4301-ABB7-838F458ED50D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC74E2FD-5B2D-4301-ABB7-838F458ED50D}.Release|Any CPU.Build.0 = Release|Any CPU
{B792333E-245B-48F0-A88E-F36EEF1F7C11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B792333E-245B-48F0-A88E-F36EEF1F7C11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B792333E-245B-48F0-A88E-F36EEF1F7C11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B792333E-245B-48F0-A88E-F36EEF1F7C11}.Release|Any CPU.Build.0 = Release|Any CPU
{B93C2373-7ADD-4D1F-B8CB-8FF32EAF364E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B93C2373-7ADD-4D1F-B8CB-8FF32EAF364E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B93C2373-7ADD-4D1F-B8CB-8FF32EAF364E}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -297,6 +291,18 @@ Global
{CEAA39C2-249C-44D0-94CF-8342CB35811D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEAA39C2-249C-44D0-94CF-8342CB35811D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEAA39C2-249C-44D0-94CF-8342CB35811D}.Release|Any CPU.Build.0 = Release|Any CPU
{A7C5D513-08D7-4BBF-9CB9-307EE91DA81D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7C5D513-08D7-4BBF-9CB9-307EE91DA81D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7C5D513-08D7-4BBF-9CB9-307EE91DA81D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7C5D513-08D7-4BBF-9CB9-307EE91DA81D}.Release|Any CPU.Build.0 = Release|Any CPU
{06FE76EC-C7D1-4C46-8047-22D58C8437A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06FE76EC-C7D1-4C46-8047-22D58C8437A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06FE76EC-C7D1-4C46-8047-22D58C8437A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06FE76EC-C7D1-4C46-8047-22D58C8437A2}.Release|Any CPU.Build.0 = Release|Any CPU
{05B6EF05-8053-45D1-8649-1779B0D7D6C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05B6EF05-8053-45D1-8649-1779B0D7D6C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05B6EF05-8053-45D1-8649-1779B0D7D6C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05B6EF05-8053-45D1-8649-1779B0D7D6C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -329,22 +335,23 @@ Global
{F026BAB4-FBBE-4AF5-8187-AA3ADF540053} = {0AF37317-F10E-47E8-A4C8-9EA886E00E40}
{D02ADFB9-822C-47BD-B5E9-4469F57CD8AB} = {F026BAB4-FBBE-4AF5-8187-AA3ADF540053}
{52003D9E-B698-4E48-BD97-3702DD8F91A9} = {F026BAB4-FBBE-4AF5-8187-AA3ADF540053}
{0987AF3F-6EFC-4AE6-9007-DE9533934D82} = {6509FEEC-F46C-4B03-82D4-8F2D78896160}
{0CE7EC46-274F-4D46-A344-1F92E1D23923} = {6509FEEC-F46C-4B03-82D4-8F2D78896160}
{0987AF3F-6EFC-4AE6-9007-DE9533934D82} = {3199F749-0082-41D0-91D3-ECED117F8B08}
{86B19A1B-17F9-410F-8B97-74FE3EE7A4BE} = {0AF37317-F10E-47E8-A4C8-9EA886E00E40}
{38508541-4429-4A30-9D84-B151250E08B8} = {86B19A1B-17F9-410F-8B97-74FE3EE7A4BE}
{35AE0870-0A6D-4F27-B534-B8DCDFD11A36} = {3234C3BB-1632-4684-838E-9D6D382D4D4D}
{FC74E2FD-5B2D-4301-ABB7-838F458ED50D} = {35AE0870-0A6D-4F27-B534-B8DCDFD11A36}
{B792333E-245B-48F0-A88E-F36EEF1F7C11} = {35AE0870-0A6D-4F27-B534-B8DCDFD11A36}
{B93C2373-7ADD-4D1F-B8CB-8FF32EAF364E} = {788A01F9-0510-441A-B05B-0CDA0EE87507}
{CABBB120-77E7-4C1D-B706-D934BE1C035C} = {788A01F9-0510-441A-B05B-0CDA0EE87507}
{75F1593B-B15D-41E5-B404-020B35A3F691} = {788A01F9-0510-441A-B05B-0CDA0EE87507}
{90B4A098-01AB-4B35-987E-838F2241DA17} = {3199F749-0082-41D0-91D3-ECED117F8B08}
{FCC70943-06B2-4743-A99D-82F5122297F3} = {3234C3BB-1632-4684-838E-9D6D382D4D4D}
{213F2EFE-F1DF-471C-A518-94D107DD543F} = {6509FEEC-F46C-4B03-82D4-8F2D78896160}
{213F2EFE-F1DF-471C-A518-94D107DD543F} = {FCC70943-06B2-4743-A99D-82F5122297F3}
{783F8A99-F164-42E3-BD7C-09D432D02DEE} = {3234C3BB-1632-4684-838E-9D6D382D4D4D}
{86CE6DBE-418E-440B-9C27-58B00AFB2FCA} = {FCC70943-06B2-4743-A99D-82F5122297F3}
{CEAA39C2-249C-44D0-94CF-8342CB35811D} = {783F8A99-F164-42E3-BD7C-09D432D02DEE}
{A7C5D513-08D7-4BBF-9CB9-307EE91DA81D} = {35AE0870-0A6D-4F27-B534-B8DCDFD11A36}
{06FE76EC-C7D1-4C46-8047-22D58C8437A2} = {35AE0870-0A6D-4F27-B534-B8DCDFD11A36}
{05B6EF05-8053-45D1-8649-1779B0D7D6C7} = {9085B4F5-E26A-471D-B25D-5D69B0337B02}
{9085B4F5-E26A-471D-B25D-5D69B0337B02} = {3234C3BB-1632-4684-838E-9D6D382D4D4D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B0CD26D-8067-4667-863E-6B0EE7EDAA42}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Examples.Mediator.MediatR
{
internal static class ConfigurationContainer
{
public static IConfiguration Configuration { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Src\RCommon.Core\RCommon.Core.csproj" />
<ProjectReference Include="..\..\..\Src\RCommon.Mediatr\RCommon.MediatR.csproj" />
</ItemGroup>

</Project>
63 changes: 63 additions & 0 deletions Examples/Mediator/Examples.Mediator.MediatR/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

using Examples.Mediator.MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.EventHandling.Producers;
using RCommon.Mediator;
using RCommon.Mediator.MediatR;
using RCommon.MediatR;
using RCommon.MediatR.Producers;
using System.Diagnostics;
using System.Reflection;
using static System.Net.Mime.MediaTypeNames;

try
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, builder) =>
{

ConfigurationContainer.Configuration = builder
.Build();
})
.ConfigureServices(services =>
{
// Configure RCommon
services.AddRCommon()
.WithMediator<MediatRBuilder>(mediator =>
{
mediator.AddNotification<TestNotification, TestNotificationHandler>();
mediator.AddRequest<TestRequest, TestRequestHandler>();
mediator.AddRequest<TestRequest, TestResponse, TestRequestHandlerWithResponse>();

// Additional configurations can be set like below
mediator.Configure(config =>
{
config.RegisterServicesFromAssemblies((typeof(Program).GetTypeInfo().Assembly));
});
});

}).Build();

Console.WriteLine("Example Starting");
var mediatorService = host.Services.GetService<IMediatorService>();
var notification = new TestNotification(DateTime.Now, Guid.NewGuid());
var request = new TestRequest(DateTime.Now, Guid.NewGuid());

await mediatorService.Publish(notification); // For multiple handlers
await mediatorService.Send(request); // For a single endpoint

var response = await mediatorService.Send<TestRequest, TestResponse>(request); // For a single endpoint with a response
Console.WriteLine("Response: {0}", response.Message);

Console.WriteLine("Example Complete");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());

}

Loading

0 comments on commit b1a17be

Please sign in to comment.