Implementing the retry pattern in c sharp using Polly

This post is the third and final installment on the retry pattern following on from implementing a simple retry pattern in c# and the retry pattern for async tasks. In the last two posts we created a retry helper class to allow us to add retry logic to applications without cluttering important application logic with retry code. Now we will solve the same problem using a popular OSS library. Polly is an open source framework for that “allows developers to express transient exception and fault handling policies such as Retry, Retry Forever, Wait and Retry, or Circuit Breaker in a fluent manner”....

December 29, 2016 · 3 min · 611 words · Alastair Crabtree

Implementing the retry pattern for async tasks in c#

This post is a follow on from Implementing a simple retry pattern in c#. Tasks, async and await are rapidly becoming be default API flavours in many dotnet libraries and the performance benefits for IO bound code have been well documented. However if you need to apply the retry pattern to some async or task returning method invocation you need to watch out for subtle errors. I’ll outline the problem and revise my solution from the previous post....

December 2, 2016 · 3 min · 470 words · Alastair Crabtree

Cache the result of an async method using LazyCache

The latests release of LazyCache, my open source cache library based on ObjectCache, makes it easy to cache the results of asynchronous or Task returning methods, so now it is simpler for you to speed up your application. Why bother with Async? Async code tends to be more efficient as you release threads while they are waiting for the response from an asynchronous resource, but at a cost of added code complexity....

September 30, 2016 · 3 min · 626 words · Alastair Crabtree

Choose the right return type for WebApi controllers

WebApi controller actions can return a variety of response types: HttpResponseMessage, IHttpActionResult, CLR objects and then the Task based variety of each for async actions. But which one is best? And how do we unit test them? Lets look at each in turn and examine why IHttpActionResult is usually the right choice. Synchronous controllers returning objects The simplest web api controller can directly return the object in question. Say you have a ProductController that is concerned with CRUD operations on Products, it might have a method like the below:...

May 30, 2016 · 4 min · 661 words · Alastair Crabtree