diff --git a/src/Infrastructure/src/EntityFrameworkCore/Uow/EntityFrameworkUnitOfWork.cs b/src/Infrastructure/src/EntityFrameworkCore/Uow/EntityFrameworkUnitOfWork.cs index 6b849960..b3fec9fb 100644 --- a/src/Infrastructure/src/EntityFrameworkCore/Uow/EntityFrameworkUnitOfWork.cs +++ b/src/Infrastructure/src/EntityFrameworkCore/Uow/EntityFrameworkUnitOfWork.cs @@ -7,6 +7,10 @@ namespace Giantnodes.Infrastructure.EntityFrameworkCore.Uow; +/// +/// Represents a unit of work implementation for Entity Framework Core. +/// +/// The type of the DbContext class. public sealed class EntityFrameworkUnitOfWork : UnitOfWork, ITransientDependency where TDbContext : DbContext { @@ -19,6 +23,7 @@ public EntityFrameworkUnitOfWork(IUnitOfWorkExecutor executor, TDbContext databa _database = database; } + /// protected override async Task OnBeginAsync(UnitOfWorkOptions options, CancellationToken cancellation = default) { if (options.Timeout.HasValue) @@ -32,6 +37,7 @@ protected override async Task OnBeginAsync(UnitOfWorkOptions options, Cancellati _transaction = await _database.Database.BeginTransactionAsync(cancellation); } + /// protected override async Task OnCommitAsync(CancellationToken cancellation = default) { var events = _database diff --git a/src/Infrastructure/src/Infrastructure/Uow/UnitOfWork.cs b/src/Infrastructure/src/Infrastructure/Uow/UnitOfWork.cs index bf83e339..e77e134d 100644 --- a/src/Infrastructure/src/Infrastructure/Uow/UnitOfWork.cs +++ b/src/Infrastructure/src/Infrastructure/Uow/UnitOfWork.cs @@ -11,25 +11,55 @@ public abstract class UnitOfWork : IUnitOfWork private bool _committed; private Exception? _exception; + /// + /// Gets the list of domain events that occurred during the execution of the unit of work. + /// protected List DomainEvents { get; } + /// + /// Gets the unique correlation identifier for this unit of work. + /// public Guid CorrelationId { get; } + /// + /// Gets the user identifier associated with this unit of work, or null if not set. + /// public Guid? UserId { get; private set; } + /// + /// Gets the tenant identifier associated with this unit of work, or null if not set. + /// public Guid? TenantId { get; private set; } + /// + /// Gets the value indicating whether this unit of work has been disposed. + /// public bool IsDisposed { get; private set; } + /// + /// Occurs when the unit of work has been successfully committed. + /// public event EventHandler? Completed; + /// + /// Occurs when an exception is thrown during the execution of the unit of work. + /// public event EventHandler? Failed; + /// + /// Occurs when the unit of work is disposed. + /// public event EventHandler? Disposed; + /// + /// Gets the options used to configure the behavior of this unit of work. + /// public UnitOfWorkOptions? Options { get; private set; } - public IReadOnlyCollection Events => DomainEvents.ToList().AsReadOnly(); + /// + /// Gets a read-only collection of domain events that occurred during the execution of the unit of work. + /// + public IReadOnlyCollection Events => DomainEvents.AsReadOnly(); protected UnitOfWork(IUnitOfWorkExecutor executor) { @@ -39,6 +69,12 @@ protected UnitOfWork(IUnitOfWorkExecutor executor) DomainEvents = new List(); } + /// + /// Begins the unit of work with the specified options. + /// + /// The options used to configure the behavior of the unit of work. + /// A to observe while waiting for the task to complete. + /// The unit of work instance. public async Task BeginAsync(UnitOfWorkOptions options, CancellationToken cancellation = default) { ArgumentNullException.ThrowIfNull(options); @@ -61,6 +97,10 @@ public async Task BeginAsync(UnitOfWorkOptions options, Cancellatio } } + /// + /// Commits the unit of work. + /// + /// A to observe while waiting for the task to complete. public async Task CommitAsync(CancellationToken cancellation = default) { if (_committed) @@ -100,7 +140,16 @@ protected virtual void Dispose(bool dispose) Disposed?.Invoke(this, EventArgs.Empty); } + /// + /// Performs any necessary initialization or setup tasks before the unit of work begins. + /// + /// The options used to configure the behavior of the unit of work. + /// A to observe while waiting for the task to complete. protected abstract Task OnBeginAsync(UnitOfWorkOptions options, CancellationToken cancellation = default); + /// + /// Performs any necessary commit operations after the unit of work has completed successfully. + /// + /// A to observe while waiting for the task to complete. protected abstract Task OnCommitAsync(CancellationToken cancellation = default); } \ No newline at end of file