RSSAmplifier

Blog

Code4IT

Recent content on Code4IT

code4it.devRSS feed ↗218 posts

Latest posts

Microsoft Agent Framework for .NET (part 2): How to use IChatClient with Azure Foundry and Ollama in .NET

IChatClient is the core of Microsoft Agent Framework. Let’s see how to configure it with Azure Foundry and Ollama.

C# Tip: Use required members to prevent invalid object initialization (beware of SetsRequiredMembers attribute!)

Learn how to use required members in C# to enforce complete object initialization at compile time and avoid half-configured models. And beware of the SetsRequiredMembers attribute, which can be dangerous if misused.

Microsoft Agent Framework for .NET (part 1): what it is, how it works, and when to use it

Microsoft Agent Framework is Microsoft’s production-oriented framework for building AI agents and multi-agent workflows in .NET and Python. Let’s see how it works, why Microsoft created it, and when to choose it over Semantic Kernel, LangChain, or AutoGen.

No more regressions with Snapshot Tests in C# using Verify: a practical guide

Snapshot Tests are an uncommon type of test that focuses on checking that no regressions were introduced after a code refactoring. Let’s learn how they work and how to use the Verify NuGet library to add them to your test suite.

Python for .NET devs: data types, classes, objects, records and interfaces

A quick comparison of data types, classes, objects, records, and interfaces in C# and Python, designed for .NET developers learning Python.

How to send Slack messages using Azure Logic Apps: built-in connector vs Slack APIs

As you may know, you can send Slack notifications using Azure Logic Apps. Yes, there is a built-in connector; but, frankly, using the Slack API gives you better results.

C# Tip: How to JSON Serialize and Deserialize values as DateTime, DateTimeOffset, DateOnly and TimeOnly

Handling dates is never trivial. And handling JSON serialization and deserialization of dates is even more difficult. And, even worse, how can you convert a value as DateTime, DateTimeOffset, DateOnly and TimeOnly?

Python for .NET devs: Introduction, virtual environments, package management, and execution lifecycle

Are you a .NET developer looking to learn Python? Me too! In this article we draw parallels between Python and .NET basic concepts, exploring virtual environments, package management with pip, and the execution lifecycle.

Readonly vs Immutable vs Frozen in C#: differences and (a lot of) benchmarks

The words ReadOnly, Immutable, Frozen seem similar but have distinct meanings in .NET. Here’s a detailed comparison of Readonly, Immutable, and Frozen collections in C#, with benchmarks and typical use cases.

Code opinion: why I prefer avoiding the Async suffix in C# asynchronous methods

Should every asynchronous method name end with Async? Does it bring more benefits or more downsides? Let’s reason about this habit, which is common among C# developers.

[C# Tip] How to create and access custom C# Attributes by using Reflection

In C#, Attributes are a handy mechanism to attach metadata to your classes, methods, properties, etc. In this article, we will see how to create custom Attributes and access them at runtime using Reflection.

Davide's Code and Architecture Notes - Metrics, Logs, and Traces: the three pillars of Observability

Learn the differences between metrics, logs, and traces - the three pillars of Observability in distributed systems - and how to use them effectively.

Things I learned after speaking at my first Big International Conference

It’s easy to say ‘Public Speaking’. But there are lots of factors that you can (and should) consider when talking to an international audience, especially if English is not your first language.

Introducing the Testing Vial: a (better?) alternative to Testing Diamond and Testing Pyramid

The Testing Pyramid focuses on Unit Tests; the Testing Diamond focuses on Integration Tests; and what about the Testing Vial?

C# Tip: injecting and testing the current time with TimeProvider and FakeTimeProvider

Dates used to be difficult to test. But with TimeProvider and FakeTimeProvider, everything becomes possible!

Build your own Static Code Analysis tool in .NET by knowing how Assembly, Type, MethodInfo, ParameterInfo work.

Why buy a whole tool when you can build your own? Learn how the Type system works in .NET, and create your own minimal type analyser.

Davide's Code and Architecture Notes - Software Architecture vs Software Design

Software Architecture and Software Design are terms that look similar but refer to two totally different aspects of software. Let’s find the differences and their purposes.

C# Tip: Handling exceptions with Task.WaitAll and Task.WhenAll

Task.WhenAll and Task.WaitAll are common methods in C# that allow you to execute multiple Tasks. But… what happens when an exception is thrown?

How to run SonarQube analysis locally with Docker

The quality of a project can be measured by having a look at how the code is written. SonarQube can help you by running static code analysis and letting you spot the pain points. Let’s learn how to install and run it locally with Docker.

Harnessing the Power of Jitter: Enhancing Retry Patterns with a bit of randomness

Operations may fail for transient reasons. How can you implement retry patterns? And how can a simple Jitter help you stabilize the system?

C# Tip: An In-Depth Look at CallerMemberName (and some Compile-Time trivia)

Let’s dive deep into the CallerMemberName attribute and explore its usage from multiple angles. We’ll see various methods of invoking it, shedding light on how it is defined at compile time.

How to log to Azure Application Insights using ILogger in ASP.NET Core

Application Insights is a great tool for handling high volumes of logs. How can you configure an ASP.NET application to send logs to Azure Application Insights? What can I do to have Application Insights log my exceptions?

D2: like Mermaid, but better. Syntax, installation, and practical usage tips

D2 is an open-source tool to design architectural layouts using a declarative syntax. It’s a textual format, which can also be stored under source control. Let’s see how it works, how you can install it, and some practical usage tips.

C# Tip: How to create Custom Attributes, and why they are useful

Applying custom attributes to C# classes and interfaces can be useful for several reasons. Let’s learn how to create Custom Attributes in C#, and let’s explore some practical usage!

HTTP Logging in ASP.NET: how to automatically log all incoming HTTP requests (and its downsides!)

Aren’t you tired of adding manual logs to your HTTP APIs to log HTTP requests and responses? By using a built-in middleware in ASP.NET, you will be able to centralize logs management and have a clear view of all the incoming HTTP requests.

Fitness Functions in Software Architecture: measuring things to ensure prosperity

Non-functional requirements matter, but we often forget to validate them. You can measure them using Fitness Functions.

C# Tip: 2 ways to generate realistic data using Bogus

Bogus is a library that generates realistic values for your data. When populating fake user names, instead of Foo and Bar, you can have John and Sarah. Let’s see two ways to define and reuse a Faker definition.

Easy logging management with Seq and ILogger in ASP.NET

Seq is one of the best Log Sinks out there : it’s easy to install and configure, and can be added to an ASP.NET application with just a line of code.

Davide's Code and Architecture Notes - the Error Management Trio, and how it affects your software architecture

When designing a software system, we naturally focus more on the happy flow. But we should carefully plan to handle errors that fall into three categories: Validation, Transient, and Fatal.

C# Tip: IEnumerable vs ICollection, and why it matters

When working with Lists in C#, you are working on a data structure that implements both ICollection and IEnumerable. What’s the difference between ICollection and IEnumerable? Why should you care about them, especially when exposing functionalities to external clients?

How to use IHttpClientFactory and WireMock.NET together using Moq

WireMock.NET is a popular library used to simulate network communication through HTTP. But there is no simple way to integrate the generated in-memory server with an instance of IHttpClientFactory injected via constructor. Right? Wrong!

Davide's Code and Architecture Notes - Practical creation of C4 Model diagrams with Structurizr

The C4 Model is one of the most famous ways to describe software architectures. Let’s see some practical usage with Strucutrizr.

C# Tip: 2 ways to use custom equality rules in a HashSet

With HashSet, you can get a list of different items in a performant way. What if you need a custom way to define when two objects are equal?

Postman's pre-request scripts: how to perform HTTP POST requests (with JSON body) and how to set Cookie authentication.

In Postman, you can define scripts to be executed before the beginning of a request. Can we use them to work with endpoints using Cookie Authentication?

Davide's Code and Architecture Notes - Web APIs vs REST APIs vs pseudo-REST APIs

When describing a web service, people often use the wrong terms. Are you really creating a REST API, or is it some sort of pseudo-REST?

C# Tip: Mark a class as Sealed to prevent subclasses creation

The sealed keyword is often ignored, yet it can be important to define a proper class design.

Seeding in-memory Entity Framework with realistic data with Bogus

You don’t need a physical database to experiment with ORMs. You can use an in-memory DB and seed the database with realistic data generated with Bogus.

Davide's Code and Architecture Notes - Arc42 Documentation, for a comprehensive description of your project

How is your project structured? What are the driving forces? If you don’t know how to express this info, you should try the Arc42 template to create a strong foundation for your documentation.

C# Tip: Path.Combine and Path.Join are similar but way different.

When composing the path to a folder or file location, the Path class can come in handy. Path.Join and Path.Combine may look similar, but their behavior differ in an unexpected way.

Getting started with Load testing with K6 on Windows 11

Can your system withstand heavy loads? You can answer this question by running Load Tests. Maybe, using K6 as a free tool.

Davide's Code and Architecture Notes - Introducing SLI, SLO, and SLA

Non-functional requirements. How can you ensure you meet them? Let’s understand SLO, SLA, and SLI, and how they affect your SDLC.

Why reaching 100% Code Coverage must NOT be your testing goal (with examples in C#)

Average teams aim at 100% Code Coverage just to reach the number. Great teams don’t. Why?

C# Tip: IFormattable interface, to define different string formats for the same object

Same object, different string representations. How do we achieve it in a standardised way?

[ENG] Improving Your Code Coverage | Microsoft Visual Studio YouTube channel

Is Random.GetItems the best way to get random items in C# 12?

You have a collection of items. You want to retrieve N elements randomly. Which alternatives do we have?

Davide's Code and Architecture Notes - Cache Expiration vs Cache Eviction (and Eviction Policies)

Caching helps your applications be more performant. However, depending on the cache size, you’ll need to sacrifice some items to make space for others. Let’s see some strategies.

How to create custom snippets in Visual Studio 2022

A simple way to improve efficiency is knowing your IDE shortcuts. Let’s learn how to create custom ones to generate code automatically.

C# Tip: ObservableCollection - a data type to intercept changes to the collection

ObservableCollection<T> is a data type that allows you to react when an item is added or removed from the collection. Let&rsquo;s learn more!

How to kill a process running on a local port in Windows

Now you can&rsquo;t run your application because another process already uses the port. How can you find that process? How to kill it?

Davide&#39;s Code and Architecture Notes - Tracking decision with Architecture Decision Records (ADRs)

When designing a system&rsquo;s architecture, you have many choices to make. How can you track them? ADRs are formal documents to track the reasons behind your decisions, giving context and info about the consequences of each choice.