Circuit Breaker with Ocelot & Polly – Part 2

In the previous blog post on Circuit Breaker with Ocelot And Polly, we saw how we could use the Ocelot library's inbuilt support for Polly to build Circuit breakers for handling timeout errors from the downstream services. In this blog post, we will address, how we could trigger a circuit breaker when the downstream service returns … Continue reading Circuit Breaker with Ocelot & Polly – Part 2

Handling Cyclic References during Serialization

In the previous post, we discussed handling subtypes during protubuf serialization. In this post, we will continue with serialization and discuss the handling of cyclic references. We will look into how cyclic references could be addressed in 3 key types of serializations. JsonXmlProtobuf As an example of cyclic references, we will address the classic example … Continue reading Handling Cyclic References during Serialization

Implementing Mediator And CQRS in .Net 6 Web Api

In some of the previous posts, we visited the Mediator and CQRS patterns, understanding the benefits it brings to the table. In this blog post, we will look into implementing the Mediator and CQRS pattern in our .Net Core Web Api application. We would be using the Mediatr library by Jimmy Bogard for the implementation of the … Continue reading Implementing Mediator And CQRS in .Net 6 Web Api

A2Z.Net : B – BackgroundService

Long-running background processes have been a need for long and for over the years, this has been accomplished in various approaches in .Net. With the introduction of Worker Service templates, it has become a lot easier to create asynchronous long-running background tasks that are supported across platforms and have inbuilt capabilities like Dependency Injection. The … Continue reading A2Z.Net : B – BackgroundService

Why is ForEach Iteration over List<T> faster than IList<T>

In this post, I would like to draw your attention to the performance implications when iterating over IList<T> and List<T> . First let us begin by writing some code to run our benchmark tests against. We will execute a simple foreach loop against IList<T> and List<T>. [Benchmark] [ArgumentsSource(nameof(IListCollection))] public void ForEachIList(IList<int> collection) { foreach (var item in collection) { DoSomething(item); } } … Continue reading Why is ForEach Iteration over List<T> faster than IList<T>

Exploring ‘With’ C# 10

C# 9 introduced us to record and the associated with operator. The with operator helped us to create or clone copies of existing record instances with set of changes specified. In C# 10, the C# team has taken the concepts a little further. Let us first examine what we could do in C# 9. public record Person { public string FirstName … Continue reading Exploring ‘With’ C# 10

.Net 6 : PeriodTimer

.NET supports various timer classes, each of which offers different functionality. As Microsoft states in its documentation, System.Timers.Timer, which fires an event and executes the code in one or more event sinks at regular intervals. The class is intended for use as a server-based or service component in a multithreaded environment; it has no user … Continue reading .Net 6 : PeriodTimer

.Net 6 : ArgumentNullException.ThrowIfNull

.Net 6 has some nice little hidden features which helps in creating cleaner code, and in this post we will look into one such feature. Previously, if we needed to check if an object is null and raise an exception, we would have done as the following. void Foo(Bar bar) { if (bar is null) … Continue reading .Net 6 : ArgumentNullException.ThrowIfNull

Json To Xml : Wrapping the Array Elements

In this post, we will look into a scenario when you need to convert a Json to XML, but at the same time need to add a wrapping Property for each array. For example, consider the following Json { reportId : 23232, submittedBy : 'Anu Viswan', projects:[ { id:1001, name:'Project 1', }, { id:1002, name:'Project … Continue reading Json To Xml : Wrapping the Array Elements