-
-
Save vkhorikov/521abe04e4c1270824edc31e4767cc7b to your computer and use it in GitHub Desktop.
When to validate commands in CQRS
This file contains hidden or 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
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; | |
} | |
} |
This file contains hidden or 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
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 */ | |
} | |
} |
This file contains hidden or 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
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