Class UnitOfWork
- Namespace
- Cratis.Chronicle.Transactions
- Assembly
- Cratis.Chronicle.dll
Represents an implementation of IUnitOfWork.
public class UnitOfWork : IUnitOfWork, IDisposable
- Inheritance
-
UnitOfWork
- Implements
- Inherited Members
Constructors
UnitOfWork(CorrelationId, Action<IUnitOfWork>, IEventStore)
Represents an implementation of IUnitOfWork.
public UnitOfWork(CorrelationId correlationId, Action<IUnitOfWork> onCompleted, IEventStore eventStore)
Parameters
correlationIdCorrelationIdThe CorrelationId for the IUnitOfWork.
onCompletedAction<IUnitOfWork>The action to call when the IUnitOfWork is completed.
eventStoreIEventStoreThe IEventStore to use for the IUnitOfWork.
Properties
CorrelationId
Gets the CorrelationId for the IUnitOfWork.
public CorrelationId CorrelationId { get; }
Property Value
IsCompleted
Gets the value indicating whether the unit of work is completed.
public bool IsCompleted { get; }
Property Value
Remarks
Unit of work being completed is semantically equal to it being disposed.
IsSuccess
Gets a value indicating whether the IUnitOfWork was successful.
public bool IsSuccess { get; }
Property Value
Methods
AddEvent(EventSequenceId, EventSourceId, object, Causation, EventStreamType?, EventStreamId?, EventSourceType?, ConcurrencyScope?)
Add an event that has occurred to the IUnitOfWork.
public void AddEvent(EventSequenceId eventSequenceId, EventSourceId eventSourceId, object @event, Causation causation, EventStreamType? eventStreamType = null, EventStreamId? eventStreamId = null, EventSourceType? eventSourceType = null, ConcurrencyScope? concurrencyScope = null)
Parameters
eventSequenceIdEventSequenceIdThe EventSequenceId for the event.
eventSourceIdEventSourceIdThe EventSourceId for the event.
eventobjectThe event that has occurred.
causationCausationThe Causation for the event.
eventStreamTypeEventStreamTypeOptional EventStreamType for the event, will default to the All stream if not set.
eventStreamIdEventStreamIdOptional EventStreamId for the event, will default to Default is not set.
eventSourceTypeEventSourceTypeOptional EventSourceType for the event, will default to Default is not set.
concurrencyScopeConcurrencyScopeOptional ConcurrencyScope for the event, will default to NotSet if not set.
Commit()
Commit the IUnitOfWork.
public Task Commit()
Returns
- Task
Awaitable task.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetAppendErrors()
Get any errors that have occurred while attempting to commit in the IUnitOfWork.
public IEnumerable<AppendError> GetAppendErrors()
Returns
- IEnumerable<AppendError>
A collection of AppendError.
GetConcurrencyViolations()
Gets any concurrency violations thar occurred in the IUnitOfWork.
public IEnumerable<ConcurrencyViolation> GetConcurrencyViolations()
Returns
- IEnumerable<ConcurrencyViolation>
A collection of ConcurrencyViolation.
GetConstraintViolations()
Gets any constraint violations that occurred in the IUnitOfWork.
public IEnumerable<ConstraintViolation> GetConstraintViolations()
Returns
- IEnumerable<ConstraintViolation>
A collection of ConstraintViolation.
GetEvents()
Get the events that have occurred in the IUnitOfWork.
public IEnumerable<object> GetEvents()
Returns
- IEnumerable<object>
A collection of events.
OnCompleted(Action<IUnitOfWork>)
Set callback to be called when completed.
public void OnCompleted(Action<IUnitOfWork> callback)
Parameters
callbackAction<IUnitOfWork>The callback to call.
Rollback()
Rollback the IUnitOfWork.
public Task Rollback()
Returns
- Task
Awaitable task.
TryGetLastCommittedEventSequenceNumber(out EventSequenceNumber?)
Try to get the EventSequenceNumber of the last committed event.
public bool TryGetLastCommittedEventSequenceNumber(out EventSequenceNumber? eventSequenceNumber)
Parameters
eventSequenceNumberEventSequenceNumberThe outputted EventSequenceNumber of the last committed event.
Returns
- bool
True if events were committed, false if not.