When XUnit run a test method, it’s going to create a new object of our test class for each and everyone of our test method. This can create a problem when the creation of the object is expensive and slow our tests down. But there’s a solution to it, we can use IClassFixture to share …
C#
Asynchronous Programming Series
Recently I wrote a series of posts regarding asynchronous programming. You can find the links to this series down below. In these series of posts I started from the definition of concurrency and how it’s different with parallelism. Then I moved on deeper into the subject by each post. My 10th post in this series …
Thread Safety
There a lot of things that can go wrong in our code. But when we introduce concurrency or parallelism in our code, we potentially could experience different set of bugs. These are race conditions, deadlocks and data corruption to name a few. This happens because there might be a share piece of data between different …
Dependency Injection: Conditional Resolving of Multiple Implementation of Interface
Sometimes we need to resolve a dependency but not with one implementation, but with multiple. There are couple of scenarios that calls for conditional resolving of types. Such as when using a generic class and methods with a dependency on another class. Now imagine the aforementioned class is an abstract one, and we need to …
What Is SynchronizationContext
SynchronizationContext is one of those topics that deserves a better understanding if we want to fully know how asynchorony works in .Net. It’s true that most of these concerns handled behind the scene. But we can benefit by understanding what exactly happens when we offload a task to a worker thread or release the thread …
Exception Handling In Asynchronous Code
It is important to know how exceptions are handled in an asynchronous program. Partly because these subtle points can sometime become a headache. When exception are thrown in a code that runs inside a task, all the exceptions are placed on the task object and returned to the calling thread. When exceptions happen, all the …
NDepend 2018 Review: A Flexible Static Analyzer
NDepend is an static analyzer which can provide various useful information about the quality of the code base. With its built in rules, it calculates how much technical debt the project is in, and estimate how many hours it takes to pay them. For the first time users, the UI might be a little overwhelming, …
Task.Run Vs TaskCompletionSource Vs Task.Factory.FromAsync
There’s a lot of small intricate details that one can miss when we deal asynchronous programs. Even though these days far more superior APIs exist that make things a lot easier. For example a lot of people think if we want to call any synchronous code asynchronously, we just simply wrap it in Task.Run. It’s …
Build UI Tree With Recursive Asp.Net Core View Component
Previous version of Asp.Net MVC had the concept of local view helpers that could contain HTML too. You see an example of this here. But this feature is removed in Asp.Net Core, but we have a better tool to do it. There might be a lot of other replacement solution for using @helper, but in …
How Functional Programming Helps With Asynchronous And Parallel Code
There is a lot of scenarios that a functional code can introduce benefits. But asynchronous and parallel programming is one of those that fit with functional programming perfectly. I’m going use one example of this in particular. That is when we write asynchronous or parallel code, we need to consciously think about how we access …