Skip to main content

Posts

Showing posts from January, 2025

Keep Your Database In Sync With Application: Fluent Migrator

In this post, we continue to explore ways to free your application from being tightly bound to the Entity Framework environment. The primary goal is to offer an alternative solution that is not only more flexible and robust but also gives you, as a developer, greater control over database manipulation with less abstraction and complexity. Here, we introduce a library for database migrations, which serves as a natural extension to tools like Dapper and SqlKata . Fluent Migrator Fluent Migrator  is a library designed for managing database migrations, giving you complete control over the execution and how migrations are written. It offers greater flexibility compared to standard EF migrations, which are closely tied to EF entities and generated automatically, often accompanied by additional overhead, including extra snapshot files. In the code snippet below, you’ll find a simple migration class. This class includes two methods that override the base Migration class, allowing you to d...

Dapper On Steroids: SqlKata

Dapper is a lightweight, high-performance ORM for .NET. It is widely used because of its simplicity and speed. Dapper in its essence provides simple mapping to POCO and works with raw queries minimizing the overhead. On the other hand it lacks of flexibility in terms of query writing, because we need to write queries like static strings. One simple example is shown in the code snippet below. using System; using System.Data.SqlClient; using Dapper; class Program { static void Main(string[] args) { using (var connection = new SqlConnection("connection_string")) { connection.Open(); string sql = "SELECT * FROM Companies"; var companies = connection.Query<Company>(sql); } } } With the lack of flexibility in query construction, we would be in temptation to go for Entity Framework or some other heavy weight ORM, but there is also a simple library ( SqlKata ) which provides a decent flexibil...

Design Patterns: Builder

This is also, like a Singleton , one of the creational design patterns. It provides the way of creating complex objects step by step by simple chaining and every particular step is independent of other steps. Let us dive into the real example of usage. For showing purpose we have created an example in C# which creates simple SQL queries using described pattern.  using System; using System.Text; namespace BuilderPatternExample { public interface ISqlQueryBuilder { ISqlQueryBuilder Select(string columns); ISqlQueryBuilder From(string table); ISqlQueryBuilder Where(string condition); ISqlQueryBuilder OrderBy(string columns); string Build(); } public class SelectQueryBuilder : ISqlQueryBuilder { private readonly StringBuilder _queryBuilder; public SelectQueryBuilder() { _queryBuilder = new StringBuilder(); } public ISqlQueryBuilder Select(string columns) { ...

Make Git Log Great (Again): Merge vs Rebase

 A well-maintained Git log is more than just a record of commits—it’s a story of your project’s growth, collaboration, and problem-solving. But as projects scale and teams grow, Git logs can become cluttered, making it harder to trace changes, understand context, or troubleshoot issues. In this post, we’ll explore strategies to make your Git log more readable, structured, and useful—because a great Git log isn’t just good practice; it’s a competitive advantage. Simple Merging Let's kick off with a simple merging strategy, the one we are all probably most familiar with. For simplification purposes, let's assume we have one main branch that represents the current development branch. Every team member creates their own branch when they want to work on a specific feature and continues working on that feature branch until it is finished. Once it's done, they merge their feature branch into the main branch, and all their work is integrated into the main branch. Then, they can mov...

Book Review: Clean Code

Undoubtedly, one of the most popular books in software engineering, it teaches the fundamentals of software architecture, methods for organizing code, and is widely regarded as a must-read for any software developer. Written by Robert C. Martin, also known as "Uncle Bob," the full title of the book is " Clean Code: A Handbook of Agile Software Craftsmanship ". Key Takeaways The book emphasizes a few important topics to pay attention to: Readability: The code should be written in a meaningful manner that is easy to read and understand. It emphasizes the importance of simple, short, clear naming for variables, functions/methods, classes, and other structures for code organization (folders, namespaces, packages), as well as maintaining consistency in naming throughout the application. This also reduces the need to write comments in the code, as the code itself should be self-explanatory. Additionally, it's important to avoid using global variables, as they often i...

Unreasonable Deadlines

“This is the last time I am doing overtime hours. It won’t happen again for sure.” You are thinking about this and in the meantime your team lead comes into the office and interrupts your thoughts with the similar story: ”Hey guys, only this time we need to do extra effort and after that we will be more concerned about deadlines.” Few months later, a new project and the same story. Sounds familiar?  Reasons This can be due to vary of reasons. Some of them could be: Poor planning is reflected by inadequate scoping and requirements. Without a clear understanding what needs to be done, it's impossible to give a good estimate. False optimism by decision makers. Tendency to not think about the details, thinking everything would go smoothly. But if something could go wrong, it will (always) ☺ Pressure from clients who are pushing for fast results to meet market demands. Underestimating external dependencies. Not giving enough attention to the third party interface integration. Hero Cultu...

Design Patterns: Singleton

Tyipically the first design pattern most people learn, often wrongly ☺ To give an introduction, we can say that singleton is one of the creational design patterns which ensures only one class instance with single point of access thru entire application.  Because it is relatively simple to implement, the Singleton pattern is sometimes misapplied in situations where it is not the most suitable choice. When to use it? Here are the few examples of corrent usage of singleton: Configuration Management  Centralized configuration settings for consistent use thru entire application Caching Maintaning  Single istance of cached objects for easy and fast acces Logging  Ensure unified mechanism to avoid duplication of log files, formats, etc Global State Management  Centralized management of the state which is needed to be shared accross the application Resource sharing  Thread pools, database connection, I/O operations When not to use it? On the other hand, here are fe...