Created
November 13, 2020 10:22
-
-
Save ginomessmer/52d9f389171dc8c16920863a09fca587 to your computer and use it in GitHub Desktop.
C# 9 Design Pattern Samples
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
public record AddGameCommand(string Title, DateTime ReleaseDate, TimeSpan HoursPlayed) | |
{ | |
public class AddGameCommandHandler | |
{ | |
// ... | |
public void Handle(AddGameCommand request) | |
{ | |
_db.Add("game", request); | |
} | |
} | |
} |
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
public record AddGameCommand(string Title, DateTime ReleaseDate, TimeSpan HoursPlayed); |
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
public record FindGameResult(string Title, DateTime ReleaseDate, TimeSpan HoursPlayed); | |
public record FindGameByTitleQuery(string Title) | |
{ | |
public class FindGameByTitleQueryHandler | |
{ | |
public FindGameResult Handler(FindGameByTitleQuery request) | |
{ | |
var game = _db.Games.SingleOrDefault(x => x.Title == request.Title); | |
var result = _mapper.Map<FindGameResult>(game); | |
return result; | |
} | |
} | |
} |
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
public record Pet(string Name, DateTime BirthDate); |
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
var pet = new Pet("Martha", new DateTime(2019, 7, 18)); | |
pet.BirthDate = DateTime.Now; // <- this will fail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment