Created
March 19, 2017 14:57
-
-
Save vladikk/86da55d0eb09d7a291b9f9a5b406f2c9 to your computer and use it in GitHub Desktop.
Command execution result object for CQRS based systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Example | |
{ | |
public abstract class ExecutionResult | |
{ | |
protected ExecutionResult(Guid aggregateId, Guid commandId, DateTime executedOn) | |
{ | |
AggregateId = aggregateId; | |
CommandId = commandId; | |
ExecutedOn = executedOn; | |
} | |
public Guid AggregateId { get; private set; } | |
public Guid CommandId { get; private set; } | |
public DateTime ExecutedOn { get; private set; } | |
public abstract bool IsSuccess { get; } | |
public class Success : ExecutionResult | |
{ | |
public Success(Guid aggregateId, Guid commandId, DateTime executedOn, int aggregateVersion) : base(aggregateId, commandId, executedOn) | |
{ | |
AggregateVersion = aggregateVersion; | |
} | |
public override bool IsSuccess => true; | |
public int AggregateVersion { get; private set; } | |
} | |
public class Success<TPayload> : Success | |
{ | |
public Success(Guid aggregateId, Guid commandId, DateTime executedOn, int aggregateVersion, TPayload data) : base(aggregateId, commandId, executedOn, aggregateVersion) | |
{ | |
Data = data; | |
} | |
public TPayload Data { get; private set; } | |
} | |
public class Failure : ExecutionResult | |
{ | |
public Failure(Guid aggregateId, Guid commandId, DateTime executedOn, string[] errorMessages) : base(aggregateId, commandId, executedOn) | |
{ | |
ErrorMessages = errorMessages; | |
} | |
public override bool IsSuccess => false; | |
public string[] ErrorMessages { get; private set; } | |
} | |
} | |
} |
What is the aggregatedId some kind of correlation id ?
AggregateId is an id of an aggregate against which the command is executed. The aggregate concepts comes from Domain-Driven Design.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the aggregatedId some kind of correlation id ?