The tales of a software developer
Latest posts
-
Test containers with Spring Boot. Persistence layer integration testing
Nowadays, there is no doubt that the quality of software and its flexibility are directly linked to the ability to verify if it still works after a change, a refactor or a new functionality. Time and effort are dedicated developing automated tests for our applications in order to keep adapting to changes while making sure our software keeps doing what it was doing before. A technology that can help us considerably when verifying that our software works as expected is Test containers. Test containers is an open-source framework that allows us to deploy infrastructure dependencies of our application when running...
-
Java 21 service with virtual threads performance test
I’m back to share the results of a comparison I was curious about: comparing the scalability of a simple microservice developed with Spring Boot. The idea behind this exercise is to test how Virtual Threads (one of the most famous Java 21 new features) impact on service availability. The service will be responsible for providing a simple REST API to store, read, modify, and delete locations in a PostgreSQL database. The code is available in the GitHub repository spring-boot-location-api. In order to develop this microservice I’ve used the traditional technological stack of Spring Boot, with the Spring Web and Spring...
-
How to log SQL queries using Entity Framework 6 like in EF Core
Watching the SQL queries Entity Framework executes is quite useful when a slow query needs optimization. If you’re already using ASP.NET Core, you might have already noticed that the debugging stream already outputs these SQL queries for you. But, if you’re working with ASP.NET MVC or ASP.NET Web API projects, by default you won’t see the SQL queries executed by EF. Even though, there’s a very simple trick to be able to see the actual SQL. Simply add the following code in your DbContext constructor. Once this piece of code has been added, you will be able to see the...
-
Why properties are evil in C#
As many of you might already know, properties are a neat way to define getters and setters. Many languages, such as C#, Delphi, Javascript or PHP support them and they are first-class citizens in the .NET ecosystem. Although properties are a handy resource, some property implementations can turn out to be evil. Very evil. Let’s dive into them. Side-effects in property code Causing side-effects is the worst practice when using properties, and it’s more spread than it seems at first. What can we consider side-effects? Modifying a nested object state, making a database query that modifies database state or change...
-
Entity Framework 6 and "There is already an open DataReader"
Entity Framework is an amazing ORM. It has differences with other ORMs like Hibernate or Doctrine, but at the same time feels more comfortable. Two key differences with other ORMs are LINQ as its query language (LINQ it’s a compiled language, if you like to rename stuff you know how many errors this feature can prevent) and being able to use foreign key values without having to join with the related entity. But, it has a poor proxy pattern. Navigation properties, the Entity Framework name for relationships between entities, can be accessed with lazy loading like in other ORMs, but...