Skip to content

Instantly share code, notes, and snippets.

@vkhorikov vkhorikov/1.cs
Last active Feb 20, 2019

Embed
What would you like to do?
When to validate commands in CQRS
public sealed class EnrollCommand : ICommand
{
public long StudentId { get; }
public string Course { get; }
public string Grade { get; }
public EnrollCommand(long studentId, string course, string grade)
{
if (course == null || grade == null) // Precondition checks
throw ArgumentException();
Id = id;
Course = course;
Grade = grade;
}
}
public sealed class EnrollCommand : ICommand
{
public long StudentId { get; }
public string Course { get; }
public string Grade { get; }
/* ... */
public static Result<EnrollCommand> Create(long studentId, string course, string grade)
{
/* Validate, return either success or failure */
}
}
public sealed class EnrollCommand : ICommand
{
public long StudentId { get; }
public string Course { get; }
public string Grade { get; }
public EnrollCommand(long studentId, string course, string grade)
{
// No invariant checks
Id = id;
Course = course;
Grade = grade;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.