Skip to content

Repository files navigation

.NetNuGet version

ResilientCommand

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.

Getting started

Step 1:

Download the NuGet package here

Install-Package ResilientCommand

Step 2:

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.

Step 3:

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);}}

Step 4:

Inject and use your command.

publicclassMyService(){privateUsersCommandusersCommand;publicMyService(UsersCommandusersCommand){this.usersCommand=usersCommand;}publicasyncTask<IEnumerable<Users>>GetUsers(CancellationTokencancellationToken){returnawaitthis.usersCommand.ExecuteAsync(cancellationToken);}}

About

A Resiliency library for wrapping dependency calls. Inspired by Hystrix

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages