mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-12 03:12:11 +08:00
refactor: refactor loading invisible assemblies
This commit is contained in:
parent
774866e9ad
commit
5115e0daec
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -17,12 +17,4 @@
|
||||
<ProjectReference Include="..\..\..\..\building-blocks\BuildingBlocks.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Booking\Bookings\" />
|
||||
<Folder Include="Booking\Data\" />
|
||||
<Folder Include="Flight\Data\Migrations\" />
|
||||
<Folder Include="Identity\Identities\" />
|
||||
<Folder Include="Passenger\Passengers\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -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<IEventMapper>(sp =>
|
||||
{
|
||||
var mappers = new IEventMapper[] {
|
||||
sp.GetRequiredService<FlightEventMapper>(),
|
||||
sp.GetRequiredService<IdentityEventMapper>(),
|
||||
sp.GetRequiredService<PassengerEventMapper>(),
|
||||
sp.GetRequiredService<BookingEventMapper>(),
|
||||
};
|
||||
|
||||
return new CompositeEventMapper(mappers);
|
||||
});
|
||||
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -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<IEventMapper, BookingEventMapper>();
|
||||
builder.Services.AddScoped<BookingEventMapper>();
|
||||
builder.AddMinimalEndpoints(assemblies: typeof(BookingRoot).Assembly);
|
||||
builder.Services.AddValidatorsFromAssembly(typeof(BookingRoot).Assembly);
|
||||
builder.Services.AddCustomMapster(typeof(BookingRoot).Assembly);
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -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<IEventMapper, FlightEventMapper>();
|
||||
builder.Services.AddScoped<FlightEventMapper>();
|
||||
builder.AddMinimalEndpoints(assemblies: typeof(FlightRoot).Assembly);
|
||||
builder.Services.AddValidatorsFromAssembly(typeof(FlightRoot).Assembly);
|
||||
builder.Services.AddCustomMapster(typeof(FlightRoot).Assembly);
|
||||
|
||||
@ -21,22 +21,6 @@
|
||||
<Protobuf Include="GrpcServer\Protos\flight.proto" GrpcServices="Both" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Unit.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Integration.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>EndToEnd.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\building-blocks\BuildingBlocks.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -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<IEventMapper, IdentityEventMapper>();
|
||||
builder.Services.AddScoped<IdentityEventMapper>();
|
||||
builder.AddMinimalEndpoints(assemblies: typeof(IdentityRoot).Assembly);
|
||||
builder.Services.AddValidatorsFromAssembly(typeof(IdentityRoot).Assembly);
|
||||
builder.Services.AddCustomMapster(typeof(IdentityRoot).Assembly);
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -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<IEventMapper, PassengerEventMapper>();
|
||||
builder.Services.AddScoped<PassengerEventMapper>();
|
||||
builder.AddMinimalEndpoints(assemblies: typeof(PassengerRoot).Assembly);
|
||||
builder.Services.AddValidatorsFromAssembly(typeof(PassengerRoot).Assembly);
|
||||
builder.Services.AddCustomMapster(typeof(PassengerRoot).Assembly);
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -13,12 +13,6 @@
|
||||
<Folder Include="GrpcClient\Protos" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Integration.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\..\building-blocks\BuildingBlocks.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -21,23 +21,8 @@
|
||||
<Protobuf Include="GrpcServer\Protos\flight.proto" GrpcServices="Both" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Unit.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Integration.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>EndToEnd.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\..\building-blocks\BuildingBlocks.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -11,12 +11,6 @@
|
||||
<Folder Include="Data\Migrations" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Integration.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\..\building-blocks\BuildingBlocks.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unit.Test")]
|
||||
[assembly: InternalsVisibleTo("Integration.Test")]
|
||||
[assembly: InternalsVisibleTo("EndToEnd.Test")]
|
||||
|
||||
@ -16,11 +16,6 @@
|
||||
<Protobuf Include="GrpcServer\Protos\passenger.proto" GrpcServices="Both" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Integration.Test</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\..\building-blocks\BuildingBlocks.csproj" />
|
||||
|
||||
37
building-blocks/Core/CompositeEventMapper.cs
Normal file
37
building-blocks/Core/CompositeEventMapper.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using BuildingBlocks.Core.Event;
|
||||
|
||||
namespace BuildingBlocks.Core;
|
||||
|
||||
public class CompositeEventMapper : IEventMapper
|
||||
{
|
||||
private readonly IEnumerable<IEventMapper> _mappers;
|
||||
|
||||
public CompositeEventMapper(IEnumerable<IEventMapper> 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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user