-
-
Save dcomartin/e5c78b9699df1c9955ba5add3159a21a to your computer and use it in GitHub Desktop.
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 class ReserveUsername : ICommand | |
{ | |
public string Username { get; set; } | |
} | |
public class ReserveUsernameHandler : IHandleMessages<ReserveUsername> | |
{ | |
private readonly UsernameReservation _usernameReservation; | |
public ReserveUsernameHandler(UsernameReservation usernameReservation) | |
{ | |
_usernameReservation = usernameReservation; | |
} | |
public async Task Handle(ReserveUsername message, IMessageHandlerContext context) | |
{ | |
Console.WriteLine($"Async: Reserving Username for {message.Username}"); | |
if (_usernameReservation.Reserve(message.Username)) | |
{ | |
var expireOptions = new SendOptions(); | |
expireOptions.DelayDeliveryWith(TimeSpan.FromSeconds(10)); | |
await context.Send(new ExpireReservation { Username = message.Username }, expireOptions); | |
await context.Publish(new UsernameReserved { Username = message.Username }); | |
} | |
} | |
} | |
public class UsernameReserved : IEvent | |
{ | |
public string Username { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment