Programming & AI Tips 💡
45.9K subscribers
67 photos
11 videos
30 files
386 links
Programming & AI:
Tips 💡
Articles 📕
AI & LLMs 👾
Design, Architecture, Principles ✅

🇳🇱 Contact: @MoienTajik
Download Telegram
Polly 🕊

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. ♻️


Installing via NuGet 🗃 :
Install-Package Polly


Usage :
public class Mailer
{
public static bool SendEmail()
{
Console.WriteLine("Sending Mail ...");

// simulate error
Random rnd = new Random();
var rndNumber = rnd.Next(1, 10);
if (rndNumber != 3)
throw new SmtpFailedRecipientException();

Console.WriteLine("Mail Sent successfully");
return true;
}
}


We retry to send the email 3 times if something failed ❌ :

var policy = Policy.Handle<SmtpFailedRecipientException>().Retry(3);
policy.Execute(Mailer.SendEmail);


🔹🔸🔹🔸

https://t.me/pgimg/79

[ Github ] : http://bit.do/pollyc

〰〰〰〰〰〰
#CSharp #RetryPattern
@ProgrammingTip