mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-29 17:25:49 +08:00
commit
50d02910df
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -12,7 +12,7 @@ on:
|
|||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
|
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
ci:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using BuildingBlocks.EventStoreDB.BackgroundWorkers;
|
using BuildingBlocks.EventStoreDB.BackgroundWorkers;
|
||||||
using BuildingBlocks.EventStoreDB.Events;
|
|
||||||
using BuildingBlocks.EventStoreDB.Projections;
|
using BuildingBlocks.EventStoreDB.Projections;
|
||||||
using BuildingBlocks.EventStoreDB.Repository;
|
using BuildingBlocks.EventStoreDB.Repository;
|
||||||
using BuildingBlocks.EventStoreDB.Subscriptions;
|
using BuildingBlocks.EventStoreDB.Subscriptions;
|
||||||
@ -11,26 +10,30 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
namespace BuildingBlocks.EventStoreDB;
|
namespace BuildingBlocks.EventStoreDB;
|
||||||
|
|
||||||
public class EventStoreDBConfig
|
using Web;
|
||||||
|
|
||||||
|
public class EventStoreOptions
|
||||||
{
|
{
|
||||||
public string ConnectionString { get; set; } = default!;
|
public string ConnectionString { get; set; } = default!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public record EventStoreDBOptions(
|
public record EventStoreDBOptions(
|
||||||
bool UseInternalCheckpointing = true
|
bool UseInternalCheckpointing = true
|
||||||
);
|
);
|
||||||
|
|
||||||
public static class EventStoreDBConfigExtensions
|
public static class EventStoreDBConfigExtensions
|
||||||
{
|
{
|
||||||
private const string DefaultConfigKey = "EventStore";
|
|
||||||
|
|
||||||
public static IServiceCollection AddEventStoreDB(this IServiceCollection services, IConfiguration config,
|
public static IServiceCollection AddEventStoreDB(this IServiceCollection services, IConfiguration config,
|
||||||
EventStoreDBOptions? options = null)
|
EventStoreDBOptions? options = null)
|
||||||
{
|
{
|
||||||
var eventStoreDBConfig = config.GetSection(DefaultConfigKey).Get<EventStoreDBConfig>();
|
|
||||||
|
|
||||||
services
|
services
|
||||||
.AddSingleton(new EventStoreClient(EventStoreClientSettings.Create(eventStoreDBConfig.ConnectionString)))
|
.AddSingleton(x=>
|
||||||
|
{
|
||||||
|
var eventStoreOptions = services.GetOptions<EventStoreOptions>(nameof(EventStoreOptions));
|
||||||
|
return new EventStoreClient(EventStoreClientSettings.Create(eventStoreOptions.ConnectionString));
|
||||||
|
})
|
||||||
.AddScoped(typeof(IEventStoreDBRepository<>), typeof(EventStoreDBRepository<>))
|
.AddScoped(typeof(IEventStoreDBRepository<>), typeof(EventStoreDBRepository<>))
|
||||||
.AddTransient<EventStoreDBSubscriptionToAll, EventStoreDBSubscriptionToAll>();
|
.AddTransient<EventStoreDBSubscriptionToAll, EventStoreDBSubscriptionToAll>();
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,8 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
|
|
||||||
namespace BuildingBlocks.EventStoreDB;
|
namespace BuildingBlocks.EventStoreDB;
|
||||||
|
|
||||||
|
using Web;
|
||||||
|
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
// ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce
|
// ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce
|
||||||
@ -13,6 +15,8 @@ public static class Extensions
|
|||||||
params Assembly[] assemblies
|
params Assembly[] assemblies
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
services.AddValidateOptions<EventStoreOptions>();
|
||||||
|
|
||||||
var assembliesToScan = assemblies.Length > 0 ? assemblies : new[] { Assembly.GetEntryAssembly()! };
|
var assembliesToScan = assemblies.Length > 0 ? assemblies : new[] { Assembly.GetEntryAssembly()! };
|
||||||
|
|
||||||
return services
|
return services
|
||||||
|
|||||||
@ -5,10 +5,8 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
|
|
||||||
namespace BuildingBlocks.PersistMessageProcessor;
|
namespace BuildingBlocks.PersistMessageProcessor;
|
||||||
|
|
||||||
using EFCore;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
|
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
@ -39,38 +37,17 @@ public static class Extensions
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IApplicationBuilder UseMigration<TContext>(this IApplicationBuilder app, IWebHostEnvironment env)
|
public static IApplicationBuilder UseMigrationPersistMessage<TContext>(this IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
where TContext : DbContext, IPersistMessageDbContext
|
where TContext : DbContext, IPersistMessageDbContext
|
||||||
{
|
{
|
||||||
MigrateDatabaseAsync<TContext>(app.ApplicationServices).GetAwaiter().GetResult();
|
using var scope = app.ApplicationServices.CreateScope();
|
||||||
|
|
||||||
if (!env.IsEnvironment("test"))
|
var persistMessageContext = scope.ServiceProvider.GetRequiredService<PersistMessageDbContext>();
|
||||||
{
|
persistMessageContext.Database.Migrate();
|
||||||
SeedDataAsync(app.ApplicationServices).GetAwaiter().GetResult();
|
|
||||||
}
|
var context = scope.ServiceProvider.GetRequiredService<TContext>();
|
||||||
|
context.Database.Migrate();
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task MigrateDatabaseAsync<TContext>(IServiceProvider serviceProvider)
|
|
||||||
where TContext : DbContext, IPersistMessageDbContext
|
|
||||||
{
|
|
||||||
using var scope = serviceProvider.CreateScope();
|
|
||||||
|
|
||||||
var persistMessageContext = scope.ServiceProvider.GetRequiredService<PersistMessageDbContext>();
|
|
||||||
await persistMessageContext.Database.MigrateAsync();
|
|
||||||
|
|
||||||
var context = scope.ServiceProvider.GetRequiredService<TContext>();
|
|
||||||
await context.Database.MigrateAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task SeedDataAsync(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
using var scope = serviceProvider.CreateScope();
|
|
||||||
var seeders = scope.ServiceProvider.GetServices<IDataSeeder>();
|
|
||||||
foreach (var seeder in seeders)
|
|
||||||
{
|
|
||||||
await seeder.SeedAllAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -278,7 +278,7 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
|
|||||||
.ToString(NumberFormatInfo.InvariantInfo)),
|
.ToString(NumberFormatInfo.InvariantInfo)),
|
||||||
new("MongoOptions:ConnectionString", MongoDbTestContainer.GetConnectionString()),
|
new("MongoOptions:ConnectionString", MongoDbTestContainer.GetConnectionString()),
|
||||||
new("MongoOptions:DatabaseName", TestContainers.MongoContainerConfiguration.Name),
|
new("MongoOptions:DatabaseName", TestContainers.MongoContainerConfiguration.Name),
|
||||||
new("EventStore:ConnectionString", EventStoreDbTestContainer.GetConnectionString())
|
new("EventStoreOptions:ConnectionString", EventStoreDbTestContainer.GetConnectionString())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -97,7 +97,6 @@ public static class TestContainers
|
|||||||
var builder = baseBuilder
|
var builder = baseBuilder
|
||||||
.WithImage(EventStoreContainerConfiguration.ImageName)
|
.WithImage(EventStoreContainerConfiguration.ImageName)
|
||||||
.WithName(EventStoreContainerConfiguration.Name)
|
.WithName(EventStoreContainerConfiguration.Name)
|
||||||
.WithPortBinding(EventStoreContainerConfiguration.Port, true)
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true"
|
"ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true"
|
||||||
},
|
},
|
||||||
"EventStore": {
|
"EventStoreOptions": {
|
||||||
"ConnectionString": "esdb://eventstore:2113?tls=false"
|
"ConnectionString": "esdb://eventstore:2113?tls=false"
|
||||||
},
|
},
|
||||||
"MongoOptions": {
|
"MongoOptions": {
|
||||||
|
|||||||
@ -48,7 +48,7 @@
|
|||||||
"BreakDuration" : 30
|
"BreakDuration" : 30
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"EventStore": {
|
"EventStoreOptions": {
|
||||||
"ConnectionString": "esdb://localhost:2113?tls=false"
|
"ConnectionString": "esdb://localhost:2113?tls=false"
|
||||||
},
|
},
|
||||||
"MongoOptions": {
|
"MongoOptions": {
|
||||||
|
|||||||
@ -18,9 +18,6 @@
|
|||||||
"ConnectionString": "mongodb://localhost:27017",
|
"ConnectionString": "mongodb://localhost:27017",
|
||||||
"DatabaseName": "booking-db-test"
|
"DatabaseName": "booking-db-test"
|
||||||
},
|
},
|
||||||
"EventStore": {
|
|
||||||
"ConnectionString": "esdb://localhost:2113?tls=false"
|
|
||||||
},
|
|
||||||
"PersistMessageOptions": {
|
"PersistMessageOptions": {
|
||||||
"Interval": 30,
|
"Interval": 30,
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
|
|||||||
@ -100,7 +100,7 @@ public static class InfrastructureExtensions
|
|||||||
});
|
});
|
||||||
app.UseCorrelationId();
|
app.UseCorrelationId();
|
||||||
app.UseHttpMetrics();
|
app.UseHttpMetrics();
|
||||||
app.UseMigration<PersistMessageDbContext>(env);
|
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
|
||||||
app.UseCustomHealthCheck();
|
app.UseCustomHealthCheck();
|
||||||
app.MapMetrics();
|
app.MapMetrics();
|
||||||
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
||||||
|
|||||||
@ -30,6 +30,7 @@ using Serilog;
|
|||||||
|
|
||||||
namespace Flight.Extensions.Infrastructure;
|
namespace Flight.Extensions.Infrastructure;
|
||||||
|
|
||||||
|
using BuildingBlocks.PersistMessageProcessor.Data;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
public static class InfrastructureExtensions
|
public static class InfrastructureExtensions
|
||||||
@ -105,6 +106,7 @@ public static class InfrastructureExtensions
|
|||||||
});
|
});
|
||||||
app.UseCorrelationId();
|
app.UseCorrelationId();
|
||||||
app.UseHttpMetrics();
|
app.UseHttpMetrics();
|
||||||
|
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
|
||||||
app.UseMigration<FlightDbContext>(env);
|
app.UseMigration<FlightDbContext>(env);
|
||||||
app.MapMetrics();
|
app.MapMetrics();
|
||||||
app.UseCustomHealthCheck();
|
app.UseCustomHealthCheck();
|
||||||
|
|||||||
@ -26,6 +26,7 @@ using Serilog;
|
|||||||
|
|
||||||
namespace Identity.Extensions.Infrastructure;
|
namespace Identity.Extensions.Infrastructure;
|
||||||
|
|
||||||
|
using BuildingBlocks.PersistMessageProcessor.Data;
|
||||||
using Configurations;
|
using Configurations;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ public static class InfrastructureExtensions
|
|||||||
{
|
{
|
||||||
options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest;
|
options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest;
|
||||||
});
|
});
|
||||||
|
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
|
||||||
app.UseMigration<IdentityContext>(env);
|
app.UseMigration<IdentityContext>(env);
|
||||||
app.UseCorrelationId();
|
app.UseCorrelationId();
|
||||||
app.UseHttpMetrics();
|
app.UseHttpMetrics();
|
||||||
|
|||||||
@ -28,6 +28,8 @@ using Serilog;
|
|||||||
|
|
||||||
namespace Passenger.Extensions.Infrastructure;
|
namespace Passenger.Extensions.Infrastructure;
|
||||||
|
|
||||||
|
using BuildingBlocks.PersistMessageProcessor.Data;
|
||||||
|
|
||||||
public static class InfrastructureExtensions
|
public static class InfrastructureExtensions
|
||||||
{
|
{
|
||||||
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
|
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
|
||||||
@ -95,6 +97,7 @@ public static class InfrastructureExtensions
|
|||||||
{
|
{
|
||||||
options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest;
|
options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest;
|
||||||
});
|
});
|
||||||
|
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
|
||||||
app.UseMigration<PassengerDbContext>(env);
|
app.UseMigration<PassengerDbContext>(env);
|
||||||
app.UseCorrelationId();
|
app.UseCorrelationId();
|
||||||
app.UseHttpMetrics();
|
app.UseHttpMetrics();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user