-
Notifications
You must be signed in to change notification settings - Fork 2
Getting Started
Alex edited this page Jun 18, 2021
·
6 revisions
Getting started is SUPER easy
Download the NuGet package here
Either add your commands as singletons/scoped yourself or use the helper
services.AddResilientCommands(typeof(Startup));
The above will look through the assembly for all Resilient Commands.
Create a command for your specific scenario (in this particular example we are using the HttpClientFactory dependency injection
class GetUsersCommand : ResilientCommand<IEnumerable<User>>
{
private readonly HttpClient client;
public GetUsersCommand(HttpClient client)
{
this.client = client;
}
protected override async Task<IEnumerable<User>> RunAsync(CancellationToken cancellationToken)
{
var response = await client.GetAsync("api/users");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<IEnumerable<User>>(content);
}
}
Inject and use your command.
public class MyService()
{
private UsersCommand usersCommand;
public MyService(UsersCommand usersCommand)
{
this.usersCommand = usersCommand;
}
public async Task<IEnumerable<Users>>GetUsers(CancellationToken cancellationToken)
{
return await this.usersCommand.ExecuteAsync(cancellationToken);
}
}
Profit.