How to Implement an Async Request Handler
public class GreetingCommand : Command
{
public GreetingCommand(string name)
: base(Guid.NewGuid())
{
Name = name;
}
public Guid Id { get; set; }
public string Name { get; private set; }
}public class GreetingCommandRequestHandlerAsync : RequestHandlerAsync<GreetingCommand>
{
public override async Task HandleAsync(GreetingCommand command, CancellationToken? ct = null)
{
var api = new IpFyApi(new Uri("https://api.ipify.org"));
var result = await api.GetAsync(ct);
Console.WriteLine("Hello {0}", command.Name);
Console.WriteLine(result.Success ? "Your public IP addres is {0}" : "Call to IpFy API failed : {0}",
result.Message);
return await base.HandleAsync(command, ct).ConfigureAwait(base.ContinueOnCapturedContext);
}
}Last updated
Was this helpful?
