In this article, we’ll continue where we left off and see how to properly handle the networking issues we had last time. Concretely, we need to find a way to host our Fargate Task in a private subnet (so it’s not reachable publicly) but also allow for outbound internet traffic through a static public IP address. We will whitelist this IP in Atlas, making the Mongo cluster accessible from the running container. …
Tag: .net
In this couple of articles, I’ll demonstrate how you can deploy a sample .NET console app to AWS and run it periodically as a Fargate task. That’s a common use case for any kind of background service you need to run on some predefined time intervals. …
How are closures implemented in C#? How do they “capture” environment variables from different scopes? The idea is simple, but it can have complex implications. That’s why it’s essential to understand the concept in detail. Let’s get some practical intuition inspecting the IL code as a source of truth. …
If you’re not careful what and when you invoke from within a critical section, you may cause a deadlock. Everything may seem correct from yours’ and your clients’ perspective, but out of a sudden, the program may go to sleep forever. In this article, I’ll demonstrate some scenarios when this can happen and what you can do(or even should do) to mitigate the risk. But first, let’s do a quick refresher on the lock statement in C# and why we …
How to avoid memory leaks? When is the Garbage Collector not going to help you? How to make sure you implement IDisposable exactly right for your use case without falling into the “overdesign trap?” Explore those topics with a lot of practical examples. …
When defining a generic interface, have you received a hint from Resharper like “The type parameter T could be declared as covariant” (or “contravariant”)? If so, have you then blindly applied the proposed refactoring which decorates your generic parameter with the in or out keyword? Like so: I know I’ve done this a few times before deciding to dig deeper into what these terms actually mean and how they affect my type’s behavior. Type variance is one of the topics …
FirstOrDefault() is one of the most (over)used IEnumerable extensions. Of course, it has its’ valid use cases not only semantically but sometimes from a performance perspective. In many cases, though, you can utilize alternative methods to convey your intentions more cleanly. …
Prefer constructor overloads or factory methods over implicit or explicit conversion operators. …
GetHashCode() is one of the functions you should probably avoid implementing yourself. It generates a lot of confusion among developers and can lead to some hard to track bugs when implemented poorly. The goal of this article is to help you understand the common mistakes developers make when implementing GetHashCode() and some general misconceptions when it comes to computing hash codes for your custom types in C#. Note that this is not a hash function design and implementation guideline. Rather, …