How to use Autofac’s interceptor feature to apply the DRY principle for session and transaction management with NHibernate

Introduction

My past articles here on Medium covered fairly low-level topics, more in the form of Lego blocks that can be used as elements for building larger components. For example, we looked at how to use transactions with NHibernate. We also introduced dependency injection (DI) with Autofac.

In this article, we will combine two elements, i.e., we’ll combine NHibernate transactions with Autofac. At a high level the benefits of this approach are:

  • Handle transactions in a single place


How to use fakes and mocks to test classes in isolation at a much faster speed

Introduction

How fast is the test suite for your backend? Can you run 10,000 tests per minute on a laptop? If you can’t then in this article, we will look at techniques that will assist getting towards that speed. And yes, I am involved in at least one project where the test suite runs at a speed of up to 10k tests per minute.

How is this possible? There are several fundamental factors to consider:

  1. Eliminate disk I/O

The first factor means that you don’t want tests to access a drive…


How to reduce complexity while making testing easier in .NET 5

In this article:

  • Benefits of Dependency Injection (DI) and Inversion of Control (IoC)

Introduction

As software engineers we are continuously tackling complexity. Any technique that makes our lives easier is welcome. Dependency injection (DI), which is one way to achieve Inversion of Control (IoC), is one such technique. It helps us breaking complex software components down into smaller, much more manageable pieces of code. In this article I’ll provide a gentle introduction to using Dependency Injection in…


How to handle parent-child relationships in .NET with Fluent Migrator’s fluent interface

A todo-list can have many to-do list items

In this article:

  • Adding a test

Introduction

Recap

In previous articles, we introduced NHibernate as the Object-Relational Mapper (ORM) to access data in a relational database. We then added transactions to keep data consistent. This will become more important in this article because we will expand our domain model with a one-to-many relationship.

Running Example

In this article, we’ll again be using as a running example a fictitious product named “Mahi”. …


Keeping your data consistent while avoiding code duplication

Boilerplate Code for Transactions

In this article:

  • What is a transaction?

Introduction

Recap

In the previous article we introduced NHibernate as the Object-Relational Mapper (ORM) to access data in a relational database. We managed to write and read objects, which was a good first step. In this article we’ll build on this and look at how we can keep data consistent.

Running Example

In this article we’ll again be using as a running example a fictitious product named “Mahi”. The word Mahi means “task” in Te Reo…


Storing and reading data in a relational database without writing SQL

Repository using NHibernate

In this article:

  • At the beginning there was a test: Using Test-Driven Development (TDD)

Introduction

Recap

In previous articles we looked at how to set up the development environment with Docker including a separate container for the relational database. We also looked at maintaining the database schema with Fluent Migrator and we updated the dev container to .NET 5.0. …


Changing the target framework and other dev environment improvements

Source: https://devblogs.microsoft.com/dotnet/introducing-net-5/

In this article:

  • Changing the .NET SDK to .NET 5.0

Introduction

Previously, we looked at how to create a dev container for .NET Core 3.1. Since then .NET 5.0 has been released. Therefore, in this article we’ll look at how upgrade the dev container to reflect those changes.

Running Example

As always, we’ll again be using as a running example a…


How to avoid issues caused by missing file change events when mounting Windows directories into a container

In this article:

  • Finding the Root Cause for issues with mounting an NTFS folder into a dev container when using WSL2

Introduction

Originally, I though this article would be about object-relational mapping (ORM) on .NET Core. Then I ran into what I thought were issues with VS Code extensions when I ran up dev containers that made use of NTFS folders mounted into the dev container.


Database Schema Maintenance with Fluent Migrator

In this article:

  • Using Fluent Migrator to maintain database schemas

Introduction

Recap

In a previous article, we created a dev container (see article “Building a Dev Container for .NET Core”). Then we added a second container to run a database server we can use during development (see article “Dockerized SQL Server for Development”). This also served as an example how we can use pre-built container images to make our lives easier as developers.

At this point we…


How to quickly spin up and use a SQL Server instance cross-platform.

Compose file with database container

In this article:

  • Containerizing the Database Server

Introduction

Recap

In my previous article I described how to create a full-time development container for .NET Core 3.1 with VS Code. The key point is that the development container (or short “dev container”) not only runs for specific tasks such like compiling, debugging, etc. The idea is to keep the dev container running all the time.

In…

Manfred Lange

I’m a Principal Consultant at boutique firm HYPR Innovation in New Zealand. Currently, my main focus is helping clients to build scalable SaaS products.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store