diff --git a/1-monolith-architecture-style/src/BookingMonolith/src/AssemblyInfo.cs b/1-monolith-architecture-style/src/BookingMonolith/src/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/1-monolith-architecture-style/src/BookingMonolith/src/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/1-monolith-architecture-style/src/BookingMonolith/src/BookingMonolith.csproj b/1-monolith-architecture-style/src/BookingMonolith/src/BookingMonolith.csproj index fb8c398..55c9efb 100644 --- a/1-monolith-architecture-style/src/BookingMonolith/src/BookingMonolith.csproj +++ b/1-monolith-architecture-style/src/BookingMonolith/src/BookingMonolith.csproj @@ -17,12 +17,4 @@ - - - - - - - - diff --git a/2-modular-monolith-architecture-style/src/Api/src/Extensions/SharedInfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Api/src/Extensions/SharedInfrastructureExtensions.cs index 2ede23d..1dbb918 100644 --- a/2-modular-monolith-architecture-style/src/Api/src/Extensions/SharedInfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Api/src/Extensions/SharedInfrastructureExtensions.cs @@ -1,4 +1,5 @@ using System.Threading.RateLimiting; +using Booking; using BuildingBlocks.Core; using BuildingBlocks.Exception; using BuildingBlocks.HealthCheck; @@ -11,7 +12,10 @@ using BuildingBlocks.PersistMessageProcessor; using BuildingBlocks.ProblemDetails; using BuildingBlocks.Web; using Figgle; +using Flight; +using Identity; using Microsoft.AspNetCore.Mvc; +using Passenger; using Serilog; namespace Api.Extensions; @@ -85,6 +89,19 @@ public static class SharedInfrastructureExtensions builder.Services.AddEasyCaching(options => { options.UseInMemory(builder.Configuration, "mem"); }); builder.Services.AddProblemDetails(); + builder.Services.AddScoped(sp => + { + var mappers = new IEventMapper[] { + sp.GetRequiredService(), + sp.GetRequiredService(), + sp.GetRequiredService(), + sp.GetRequiredService(), + }; + + return new CompositeEventMapper(mappers); + }); + + return builder; } diff --git a/2-modular-monolith-architecture-style/src/Modules/Booking/src/AssemblyInfo.cs b/2-modular-monolith-architecture-style/src/Modules/Booking/src/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/2-modular-monolith-architecture-style/src/Modules/Booking/src/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs index e931b44..60ef44d 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Booking/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -1,5 +1,4 @@ using Booking.Data; -using BuildingBlocks.Core; using BuildingBlocks.EventStoreDB; using BuildingBlocks.Mapster; using BuildingBlocks.Mongo; @@ -14,7 +13,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddBookingModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(BookingRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(BookingRoot).Assembly); builder.Services.AddCustomMapster(typeof(BookingRoot).Assembly); diff --git a/2-modular-monolith-architecture-style/src/Modules/Flight/src/AssemblyInfo.cs b/2-modular-monolith-architecture-style/src/Modules/Flight/src/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/2-modular-monolith-architecture-style/src/Modules/Flight/src/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs index e5288ea..f54c81e 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Flight/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -1,4 +1,3 @@ -using BuildingBlocks.Core; using BuildingBlocks.EFCore; using BuildingBlocks.Mapster; using BuildingBlocks.Mongo; @@ -17,7 +16,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddFlightModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(FlightRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(FlightRoot).Assembly); builder.Services.AddCustomMapster(typeof(FlightRoot).Assembly); diff --git a/2-modular-monolith-architecture-style/src/Modules/Flight/src/Flight.csproj b/2-modular-monolith-architecture-style/src/Modules/Flight/src/Flight.csproj index 3fd1c13..3ddedde 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Flight/src/Flight.csproj +++ b/2-modular-monolith-architecture-style/src/Modules/Flight/src/Flight.csproj @@ -21,22 +21,6 @@ - - - <_Parameter1>Unit.Test - - - - - <_Parameter1>Integration.Test - - - - - <_Parameter1>EndToEnd.Test - - - diff --git a/2-modular-monolith-architecture-style/src/Modules/Identity/src/AssemblyInfo.cs b/2-modular-monolith-architecture-style/src/Modules/Identity/src/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/2-modular-monolith-architecture-style/src/Modules/Identity/src/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs index 7c5c9dd..900be81 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Identity/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -1,9 +1,7 @@ -using BuildingBlocks.Core; using BuildingBlocks.EFCore; using BuildingBlocks.Mapster; using BuildingBlocks.Web; using FluentValidation; -using Identity.Configurations; using Identity.Data; using Identity.Data.Seed; using Microsoft.AspNetCore.Builder; @@ -17,7 +15,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddIdentityModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(IdentityRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(IdentityRoot).Assembly); builder.Services.AddCustomMapster(typeof(IdentityRoot).Assembly); diff --git a/2-modular-monolith-architecture-style/src/Modules/Passenger/src/AssemblyInfo.cs b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs index 52646b9..3487d26 100644 --- a/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/2-modular-monolith-architecture-style/src/Modules/Passenger/src/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -1,4 +1,3 @@ -using BuildingBlocks.Core; using BuildingBlocks.EFCore; using BuildingBlocks.Mapster; using BuildingBlocks.Mongo; @@ -15,7 +14,7 @@ public static class InfrastructureExtensions { public static WebApplicationBuilder AddPassengerModules(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.AddMinimalEndpoints(assemblies: typeof(PassengerRoot).Assembly); builder.Services.AddValidatorsFromAssembly(typeof(PassengerRoot).Assembly); builder.Services.AddCustomMapster(typeof(PassengerRoot).Assembly); diff --git a/3-microservices-architecture-style/src/Services/Booking/src/Booking/AssemblyInfo.cs b/3-microservices-architecture-style/src/Services/Booking/src/Booking/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/3-microservices-architecture-style/src/Services/Booking/src/Booking/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/3-microservices-architecture-style/src/Services/Booking/src/Booking/Booking.csproj b/3-microservices-architecture-style/src/Services/Booking/src/Booking/Booking.csproj index 0764bb5..69ca1ab 100644 --- a/3-microservices-architecture-style/src/Services/Booking/src/Booking/Booking.csproj +++ b/3-microservices-architecture-style/src/Services/Booking/src/Booking/Booking.csproj @@ -13,12 +13,6 @@ - - - <_Parameter1>Integration.Test - - - diff --git a/3-microservices-architecture-style/src/Services/Flight/src/Flight/AssemblyInfo.cs b/3-microservices-architecture-style/src/Services/Flight/src/Flight/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/3-microservices-architecture-style/src/Services/Flight/src/Flight/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/3-microservices-architecture-style/src/Services/Flight/src/Flight/Flight.csproj b/3-microservices-architecture-style/src/Services/Flight/src/Flight/Flight.csproj index f8b586c..7471005 100644 --- a/3-microservices-architecture-style/src/Services/Flight/src/Flight/Flight.csproj +++ b/3-microservices-architecture-style/src/Services/Flight/src/Flight/Flight.csproj @@ -21,23 +21,8 @@ - - - <_Parameter1>Unit.Test - - - - - <_Parameter1>Integration.Test - - - - - <_Parameter1>EndToEnd.Test - - - + diff --git a/3-microservices-architecture-style/src/Services/Identity/src/Identity/AssemblyInfo.cs b/3-microservices-architecture-style/src/Services/Identity/src/Identity/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/3-microservices-architecture-style/src/Services/Identity/src/Identity/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Identity.csproj b/3-microservices-architecture-style/src/Services/Identity/src/Identity/Identity.csproj index fb89397..2662e88 100644 --- a/3-microservices-architecture-style/src/Services/Identity/src/Identity/Identity.csproj +++ b/3-microservices-architecture-style/src/Services/Identity/src/Identity/Identity.csproj @@ -11,12 +11,6 @@ - - - <_Parameter1>Integration.Test - - - diff --git a/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/AssemblyInfo.cs b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/AssemblyInfo.cs new file mode 100644 index 0000000..60fedfd --- /dev/null +++ b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unit.Test")] +[assembly: InternalsVisibleTo("Integration.Test")] +[assembly: InternalsVisibleTo("EndToEnd.Test")] + diff --git a/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Passenger.csproj b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Passenger.csproj index 6530411..8e453b0 100644 --- a/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Passenger.csproj +++ b/3-microservices-architecture-style/src/Services/Passenger/src/Passenger/Passenger.csproj @@ -16,11 +16,6 @@ - - - <_Parameter1>Integration.Test - - diff --git a/building-blocks/Core/CompositeEventMapper.cs b/building-blocks/Core/CompositeEventMapper.cs new file mode 100644 index 0000000..3f309f7 --- /dev/null +++ b/building-blocks/Core/CompositeEventMapper.cs @@ -0,0 +1,37 @@ +using BuildingBlocks.Core.Event; + +namespace BuildingBlocks.Core; + +public class CompositeEventMapper : IEventMapper +{ + private readonly IEnumerable _mappers; + + public CompositeEventMapper(IEnumerable mappers) + { + _mappers = mappers; + } + + public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event) + { + foreach (var mapper in _mappers) + { + var integrationEvent = mapper.MapToIntegrationEvent(@event); + if (integrationEvent is not null) + return integrationEvent; + } + + return null; + } + + public IInternalCommand? MapToInternalCommand(IDomainEvent @event) + { + foreach (var mapper in _mappers) + { + var internalCommand = mapper.MapToInternalCommand(@event); + if (internalCommand is not null) + return internalCommand; + } + + return null; + } +}