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