A Resiliency library for wrapping dependency calls. Heavily inspired by Hystrix
The idea is simple; protect against up/down- stream problems, by encapsulating calls to these dependencies in reliability patterns. This project seeks to do just that.
There is a Getting-Started Guide here.
Please check the wiki for more information
or the examples some usage examples.
Download the NuGet package here
Install-Package ResilientCommandEither 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
classGetUsersCommand:ResilientCommand<IEnumerable<User>>{privatereadonlyHttpClientclient;publicGetUsersCommand(HttpClientclient){this.client=client;}protectedoverrideasyncTask<IEnumerable<User>>RunAsync(CancellationTokencancellationToken){varresponse=awaitclient.GetAsync("api/users");response.EnsureSuccessStatusCode();varcontent=awaitresponse.Content.ReadAsStringAsync();returnJsonConvert.DeserializeObject<IEnumerable<User>>(content);}}Inject and use your command.
publicclassMyService(){privateUsersCommandusersCommand;publicMyService(UsersCommandusersCommand){this.usersCommand=usersCommand;}publicasyncTask<IEnumerable<Users>>GetUsers(CancellationTokencancellationToken){returnawaitthis.usersCommand.ExecuteAsync(cancellationToken);}}