Skip to content

Instantly share code, notes, and snippets.

@ginomessmer
Created November 13, 2020 10:22
Show Gist options
  • Save ginomessmer/52d9f389171dc8c16920863a09fca587 to your computer and use it in GitHub Desktop.
Save ginomessmer/52d9f389171dc8c16920863a09fca587 to your computer and use it in GitHub Desktop.
C# 9 Design Pattern Samples
public record AddGameCommand(string Title, DateTime ReleaseDate, TimeSpan HoursPlayed)
{
public class AddGameCommandHandler
{
// ...
public void Handle(AddGameCommand request)
{
_db.Add("game", request);
}
}
}
public record AddGameCommand(string Title, DateTime ReleaseDate, TimeSpan HoursPlayed);
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;
}
}
}
public record Pet(string Name, DateTime BirthDate);
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