Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
akbaramd committed Dec 31, 2024
1 parent e7f65b4 commit 28fd916
Show file tree
Hide file tree
Showing 21 changed files with 505 additions and 816 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public EfCoreUnitofWOrkTransactionManager(IPayehDbContext dbContext, IDbContextT
/// <summary>
/// Commits the current transaction.
/// </summary>
public async Task CommitTransactionAsync()
public async Task CommitTransactionAsync(CancellationToken cancellationToken)
{
try
{
await _transaction?.CommitAsync()!;
await _transaction?.CommitAsync(cancellationToken)!;
}
catch (Exception ex)
{
Expand All @@ -37,11 +37,11 @@ public async Task CommitTransactionAsync()
/// <summary>
/// Rolls back the current transaction.
/// </summary>
public async Task RollbackTransactionAsync()
public async Task RollbackTransactionAsync(CancellationToken cancellationToken)
{
try
{
await _transaction?.RollbackAsync()!;
await _transaction?.RollbackAsync(cancellationToken)!;
}
catch (Exception ex)
{
Expand Down
24 changes: 11 additions & 13 deletions New/Payeh.SharedKernel/UnitOfWork/ChildUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using MediatR;
using Payeh.SharedKernel.EntityFrameworkCore;

namespace Payeh.SharedKernel.UnitOfWork.Child
namespace Payeh.SharedKernel.UnitOfWork
{
/// <summary>
/// A child UnitOfWork that delegates all operations to a parent <see cref="IUnitOfWork"/>.
Expand Down Expand Up @@ -53,14 +52,13 @@ public void AddTransaction(string key, IUnitofWOrkTransactionManager unitofWOrkT
public IEnumerable<string> GetTransactionKeys()
=> _parentUow.GetTransactionKeys();

public void CommitTransaction(string key)
=> _parentUow.CommitTransaction(key);



public Task CommitTransactionAsync(string key, CancellationToken cancellationToken = default)
=> _parentUow.CommitTransactionAsync(key, cancellationToken);

public void RollbackTransaction(string key)
=> _parentUow.RollbackTransaction(key);


public Task RollbackTransactionAsync(string key, CancellationToken cancellationToken = default)
=> _parentUow.RollbackTransactionAsync(key, cancellationToken);
Expand All @@ -86,28 +84,28 @@ public IEnumerable<string> GetDataStorageKeys()
/// Typically, a child does not finalize (commit) the entire UoW.
/// However, you can choose to delegate it to the parent if desired.
/// </summary>
public void CommitAll()
=> _parentUow.CommitAll();


public Task CommitAsync(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
public void RollbackAll()
=> _parentUow.RollbackAll();


public Task RollbackAsync(CancellationToken cancellationToken = default)
=> _parentUow.RollbackAsync(cancellationToken);

public void Initialize(IUnitOfWorkOptions options)
=> _parentUow.Initialize(options);


public void AddDomainEvent(INotification domainEvent)
{
_parentUow.AddDomainEvent(domainEvent);
}


public void Initialize(IUnitOfWorkOptions options)
{
_parentUow.Initialize(options);
}

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public interface IUnitOfWOrtDatabaseManager
{
Task SaveChangesAsync(CancellationToken cancellationToken = default);
IEnumerable<IDomainEvent> GetDomainEvents();
void ClearDomainEvents();

void Dispose();
}
9 changes: 3 additions & 6 deletions New/Payeh.SharedKernel/UnitOfWork/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public interface IUnitOfWork : IDisposable
void AddTransaction(string key, IUnitofWOrkTransactionManager unitofWOrkTransactionManager);
IUnitofWOrkTransactionManager? GetTransaction(string key);
IEnumerable<string> GetTransactionKeys();
void CommitTransaction(string key);
Task CommitTransactionAsync(string key, CancellationToken cancellationToken = default);
void RollbackTransaction(string key);
Task RollbackTransactionAsync(string key, CancellationToken cancellationToken = default);

// Database/Storage Management
Expand All @@ -33,11 +31,10 @@ public interface IUnitOfWork : IDisposable
IEnumerable<string> GetDataStorageKeys();

// Global Operations
void CommitAll();

Task CommitAsync(CancellationToken cancellationToken = default);
void RollbackAll();

Task RollbackAsync(CancellationToken cancellationToken = default);
void Initialize(IUnitOfWorkOptions options);

// Domain Events Management
/// <summary>
Expand All @@ -46,7 +43,7 @@ public interface IUnitOfWork : IDisposable
/// <param name="domainEvent">The domain event to add.</param>
void AddDomainEvent(INotification domainEvent);


void Initialize(IUnitOfWorkOptions options);
}

// Supporting Interfaces for Transaction and Data Storage Managers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public interface IUnitofWOrkTransactionManager
{

Task CommitTransactionAsync();
Task RollbackTransactionAsync();
Task CommitTransactionAsync(CancellationToken cancellationToken);
Task RollbackTransactionAsync(CancellationToken cancellationToken);
void Dispose();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ private NullUnitofWOrkTransactionManager() { }

public void BeginTransaction() { }

public Task CommitTransactionAsync()
public Task CommitTransactionAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task RollbackTransactionAsync()
public Task RollbackTransactionAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
Expand Down
Loading

0 comments on commit 28fd916

Please sign in to comment.