mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-25 23:04:05 +08:00
commit
f400fe511d
@ -7,7 +7,9 @@
|
||||
|
||||
image:
|
||||
file: .gitpod.Dockerfile
|
||||
|
||||
|
||||
# https://www.gitpod.io/docs/configure/workspaces/tasks#execution-order
|
||||
# https://www.gitpod.io/docs/configure/projects/prebuilds
|
||||
tasks:
|
||||
- name: Init Docker-Compose
|
||||
# https://www.gitpod.io/docs/configure/projects/prebuilds
|
||||
|
||||
1
gitpod.Dockerfile
Normal file
1
gitpod.Dockerfile
Normal file
@ -0,0 +1 @@
|
||||
FROM gitpod/workspace-dotnet:latest
|
||||
@ -35,6 +35,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
|
||||
<PackageReference Include="Mongo2Go" Version="3.1.3" />
|
||||
<PackageReference Include="Npgsql" Version="7.0.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.4.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.0.0-rc9.7" />
|
||||
<PackageReference Include="Polly" Version="7.2.3" />
|
||||
|
||||
@ -25,7 +25,7 @@ namespace BuildingBlocks.Core.Model
|
||||
return dequeuedEvents;
|
||||
}
|
||||
|
||||
public long Version { get; set; } = -1;
|
||||
public long Version { get; set; }
|
||||
|
||||
public TId Id { get; set; }
|
||||
}
|
||||
|
||||
@ -7,13 +7,16 @@ using Microsoft.EntityFrameworkCore.Storage;
|
||||
|
||||
namespace BuildingBlocks.EFCore;
|
||||
|
||||
using System.Data;
|
||||
|
||||
public abstract class AppDbContextBase : DbContext, IDbContext
|
||||
{
|
||||
private readonly ICurrentUserProvider _currentUserProvider;
|
||||
|
||||
private IDbContextTransaction _currentTransaction;
|
||||
|
||||
protected AppDbContextBase(DbContextOptions options, ICurrentUserProvider currentUserProvider = null) : base(options)
|
||||
protected AppDbContextBase(DbContextOptions options, ICurrentUserProvider currentUserProvider = null) :
|
||||
base(options)
|
||||
{
|
||||
_currentUserProvider = currentUserProvider;
|
||||
}
|
||||
@ -30,7 +33,7 @@ public abstract class AppDbContextBase : DbContext, IDbContext
|
||||
return;
|
||||
}
|
||||
|
||||
_currentTransaction ??= await Database.BeginTransactionAsync(cancellationToken);
|
||||
_currentTransaction ??= await Database.BeginTransactionAsync(IsolationLevel.ReadCommitted, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task CommitTransactionAsync(CancellationToken cancellationToken = default)
|
||||
@ -68,7 +71,16 @@ public abstract class AppDbContextBase : DbContext, IDbContext
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
OnBeforeSaving();
|
||||
return base.SaveChangesAsync(cancellationToken);
|
||||
try
|
||||
{
|
||||
return base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (DbUpdateConcurrencyException ex)
|
||||
{
|
||||
var data = ex.Entries.Single();
|
||||
data.OriginalValues.SetValues(data.GetDatabaseValues() ?? throw new InvalidOperationException());
|
||||
return base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<IDomainEvent> GetDomainEvents()
|
||||
@ -104,7 +116,6 @@ public abstract class AppDbContextBase : DbContext, IDbContext
|
||||
case EntityState.Added:
|
||||
entry.Entity.CreatedBy = userId;
|
||||
entry.Entity.CreatedAt = DateTime.Now;
|
||||
entry.Entity.Version++;
|
||||
break;
|
||||
|
||||
case EntityState.Modified:
|
||||
|
||||
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(PersistMessageDbContext))]
|
||||
[Migration("20230113183839_initial")]
|
||||
[Migration("20230120222214_initial")]
|
||||
partial class initial
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -1,5 +1,4 @@
|
||||
using BuildingBlocks.Core.Model;
|
||||
using BuildingBlocks.IdsGenerator;
|
||||
using Flight.Aircrafts.Features.CreateAircraft.Events.Domain.V1;
|
||||
|
||||
namespace Flight.Aircrafts.Models;
|
||||
|
||||
@ -8,8 +8,13 @@ public class AircraftConfiguration : IEntityTypeConfiguration<Aircraft>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Aircraft> builder)
|
||||
{
|
||||
|
||||
builder.ToTable(nameof(Aircraft));
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||
|
||||
|
||||
// // ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,9 +8,14 @@ public class AirportConfiguration: IEntityTypeConfiguration<Airport>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Airport> builder)
|
||||
{
|
||||
|
||||
builder.ToTable(nameof(Airport));
|
||||
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||
|
||||
|
||||
// // ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,10 @@ public class FlightConfiguration : IEntityTypeConfiguration<Flights.Models.Fligh
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||
|
||||
|
||||
// // ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
|
||||
builder
|
||||
.HasOne<Aircraft>()
|
||||
.WithMany()
|
||||
|
||||
@ -16,6 +16,9 @@ public class SeatConfiguration : IEntityTypeConfiguration<Seat>
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||
|
||||
// // ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
|
||||
builder
|
||||
.HasOne<Flights.Models.Flight>()
|
||||
.WithMany()
|
||||
|
||||
@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Flight.Data;
|
||||
|
||||
|
||||
public sealed class FlightDbContext : AppDbContextBase
|
||||
{
|
||||
public FlightDbContext(DbContextOptions<FlightDbContext> options, ICurrentUserProvider currentUserProvider) : base(
|
||||
|
||||
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace Flight.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlightDbContext))]
|
||||
[Migration("20230113183335_Init")]
|
||||
[Migration("20230120222458_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -64,6 +64,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -112,6 +113,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -191,6 +193,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -255,6 +258,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("type");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -61,6 +61,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -109,6 +110,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -188,6 +190,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -252,6 +255,7 @@ namespace Flight.Data.Migrations
|
||||
.HasColumnName("type");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using BuildingBlocks.EFCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
@ -12,5 +11,8 @@ public class PassengerConfiguration: IEntityTypeConfiguration<Passengers.Models.
|
||||
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||
|
||||
// // ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ using Passenger.Data;
|
||||
namespace Passenger.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(PassengerDbContext))]
|
||||
[Migration("20230113183717_initial")]
|
||||
[Migration("20230120222631_initial")]
|
||||
partial class initial
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -68,6 +68,7 @@ namespace Passenger.Data.Migrations
|
||||
.HasColumnName("passport_number");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
@ -65,6 +65,7 @@ namespace Passenger.Data.Migrations
|
||||
.HasColumnName("passport_number");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user