Skip to content

Commit

Permalink
Added UnitOfWork.Init
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinRyazantsev committed Aug 12, 2020
1 parent 0e71e79 commit e6dcf4a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
7 changes: 6 additions & 1 deletion src/Swisschain.Extensions.Idempotency/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ public interface IUnitOfWork : IAsyncDisposable
bool IsCommitted { get; }
bool IsRolledBack { get; }
Outbox Outbox { get; }


Task Init(IIdGeneratorRepository idGeneratorRepository,
IOutboxWriteRepository outboxWriteRepository,
string idempotencyId,
Outbox outbox);

/// <summary>
/// Closes the <see cref="Outbox"/> and commits unit of work transaction
/// </summary>
Expand Down
32 changes: 18 additions & 14 deletions src/Swisschain.Extensions.Idempotency/UnitOfWorkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,35 @@ public abstract class UnitOfWorkBase : IUnitOfWork
{
private readonly IOutboxDispatcher _defaultOutboxDispatcher;

public UnitOfWorkBase(
IOutboxWriteRepository outboxWriteRepository,
IIdGeneratorRepository idGeneratorRepository,
string idempotencyId,
Outbox outbox,
IOutboxDispatcher defaultOutboxDispatcher)
public UnitOfWorkBase(IOutboxDispatcher defaultOutboxDispatcher)
{
_defaultOutboxDispatcher = defaultOutboxDispatcher;
OutboxWriteRepository = outboxWriteRepository;
IdGeneratorRepository = idGeneratorRepository;
IdempotencyId = idempotencyId;
Outbox = outbox;
}

public IIdGeneratorRepository IdGeneratorRepository { get; }
public IOutboxWriteRepository OutboxWriteRepository { get; }
public string IdempotencyId { get; }
public IIdGeneratorRepository IdGeneratorRepository { get; private set; }
public IOutboxWriteRepository OutboxWriteRepository { get; private set; }
public string IdempotencyId { get; private set; }
public bool IsCommitted { get; private set; }
public bool IsRolledBack { get; private set; }
public Outbox Outbox { get; }
public Outbox Outbox { get; private set; }

protected abstract Task CommitImpl();
protected abstract Task RollbackImpl();
protected abstract ValueTask DisposeAsync(bool disposing);

public Task Init(IIdGeneratorRepository idGeneratorRepository,
IOutboxWriteRepository outboxWriteRepository,
string idempotencyId,
Outbox outbox)
{
OutboxWriteRepository = outboxWriteRepository;
IdGeneratorRepository = idGeneratorRepository;
IdempotencyId = idempotencyId;
Outbox = outbox;

return Task.CompletedTask;
}

public async Task Commit()
{
if (IsCommitted)
Expand Down
13 changes: 2 additions & 11 deletions tests/Tests/ExampleUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ namespace Tests
{
public class ExampleUnitOfWork : UnitOfWorkBase
{
public ExampleUnitOfWork(IOutboxWriteRepository outboxWriteRepository,
IIdGeneratorRepository idGeneratorRepository,
string idempotencyId,
Outbox outbox,
IOutboxDispatcher defaultOutboxDispatcher) :

base(outboxWriteRepository,
idGeneratorRepository,
idempotencyId,
outbox,
defaultOutboxDispatcher)
public ExampleUnitOfWork(IOutboxDispatcher defaultOutboxDispatcher) :
base(defaultOutboxDispatcher)
{
}

Expand Down

0 comments on commit e6dcf4a

Please sign in to comment.