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

Introduction

  • Handle transactions in a single place
  • Handle transaction-related exceptions in a single place
  • Retry transactions in a single place
  • Change transactional behavior of classes by changing a single line…


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

Introduction

  1. Eliminate disk I/O
  2. Eliminate cross-process interaction
  3. Test each class and method in isolation


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

  • Benefits of Dependency Injection (DI) and Inversion of Control (IoC)
  • What is the problem to be solved?
  • Basic DI concepts
  • DI in a console application
  • Autofac in an ASP.NET web application in .NET 5.0

Introduction


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

A todo-list can have many to-do list items
  • Adding a test
  • Extending the domain model
  • Updating the object-relational mapping code
  • Resolving common NHibernate and database exceptions
  • Lazy Loading
  • Simplifying mapping code by using conventions

Introduction

Recap

Running Example


Boilerplate Code for Transactions
  • What is a transaction?
  • Transactions in NHibernate
  • Rolling back transactions
  • Removing duplicated boilerplate code
  • Some house keeping

Introduction

Recap

Running Example


Repository using NHibernate
  • At the beginning there was a test: Using Test-Driven Development (TDD)
  • A simple domain class
  • Using an object-relational mapper (ORM): NHibernate
  • Mapping classes to tables with Fluent NHibernate
  • Using the repository pattern to encapsulate database access

Introduction

Recap


Source: https://devblogs.microsoft.com/dotnet/introducing-net-5/
  • Changing the .NET SDK to .NET 5.0
  • Adding a missing tool required by some VS Code extensions
  • Adding an entrypoint script to improve running as non-root
  • Installing dotnet-outdated-tool for keeping nuget packages up-to-date
  • Switching the target framework to .NET 5.0

Introduction

Running Example


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

  • Finding the Root Cause for issues with mounting an NTFS folder into a dev container when using WSL2
  • Installing Windows Subsystem for Linux, version 2 (WSL2)
  • Installing Linux distro in WSL2
  • Configuring git for use in Linux distro
  • Launching VS Code in Linux distro
  • Launching and connecting to dev container
  • Avoiding common pitfalls

Introduction


  • Using Fluent Migrator to maintain database schemas
  • Writing and applying database schema migrations
  • A Database class to keep things simple
  • Using up-only migrations to simplify migrations

Introduction

Recap


Compose file with database container
  • Containerizing the Database Server
  • Extending the dev container with a database server container
  • Automatically starting the database server
  • Automatically creating the database
  • Connecting to the database from the host

Introduction

Recap

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