Skip to main content
  1. Categories/

Clean Architecture

Validating Inputs with FluentValidation

Deep Dive .NET · Dec 1, 2024 · 6 min read
Introduction # Validation is the one part of a request I refuse to trust anywhere but the edge. Domain objects assume they are already valid; rejecting a malformed email or a missing name belongs at the API boundary, before that data reaches a service or a repository.
Validating Inputs with FluentValidation

Using Dapper for Data Access and Repository Pattern

Deep Dive .NET · Dec 1, 2024 · 9 min read
Introduction # On the Contact Management Application I reached for Dapper instead of Entity Framework Core, and the reason was boring: I wanted to see the SQL. EF Core is fine until a generated query does something surprising under load, and then you are reverse-engineering LINQ translations at 2 a.m.
Using Dapper for Data Access and Repository Pattern

Implementing AutoMapper for DTO Mapping with Audit Details

Deep Dive .NET · Dec 1, 2024 · 6 min read
Early versions of the Contact Management Application had the same four lines at the end of every create and update method: set CreatedBy, set CreatedOn (or their Updated* twins), then save. Copy-pasted audit code gets forgotten just often enough to make the audit columns untrustworthy, and an audit column you can’t trust is worse than none. Moving that logic into AutoMapper profiles fixed it in one place.
Implementing AutoMapper for DTO Mapping with Audit Details

Implementing Activity Logging with Custom Attributes

Deep Dive .NET · Dec 1, 2024 · 6 min read
The first version of audit logging in the Contact Management Application was what most codebases end up with: _logger.LogInformation("Creating contact...") copy-pasted into every controller action. It worked, until someone forgot one, and the one they forgot was of course the action the auditors asked about. Logging that depends on developer discipline isn’t an audit trail; it’s a suggestion.
Implementing Activity Logging with Custom Attributes

Handling Authorization and Role-Based Access Control (RBAC)

Deep Dive .NET · Dec 1, 2024 · 19 min read
Introduction # Static role checks ([Authorize(Roles = "Admin")]) fall apart the first time someone asks you to add a permission without a redeploy. Once roles and permissions have to change at runtime, hard-coded role attributes become a liability. The Contact Management Application takes a different route: a dynamic policy provider that builds authorization policies from the database at request time, covering both the backend API and the Angular frontend, wired into JWT authentication without breaking the separation of concerns Clean Architecture expects.
Handling Authorization and Role-Based Access Control (RBAC)

Error Handling and Exception Management in the API

Deep Dive .NET · Dec 1, 2024 · 6 min read
An unhandled exception in a default ASP.NET Core API gives the client an empty 500 and gives you a stack trace in a log nobody is watching. The only thing worse is the API that returns the stack trace to the caller. The Contact Management Application takes the middle path: one middleware catches everything, maps known exception types to sensible status codes, returns a predictable JSON shape, and logs the details server-side. This post walks through that implementation and where I would lean on the newer built-in alternatives instead.
Error Handling and Exception Management in the API

Dependency Injection Setup Across Layers

Deep Dive .NET · Dec 1, 2024 · 6 min read
Program.cs is where service registration goes to rot. It starts at five lines, then every feature adds its repositories, validators, and settings bindings until nobody can tell which layer owns what. The Contact Management Application avoids that with one rule: each layer registers its own services through an extension method, and Program.cs only calls those methods. This post walks through that setup layer by layer, using the real code, including two spots where the real code deserves a warning label.
Dependency Injection Setup Across Layers

Clean Architecture: Introduction to the Project Structure

Deep Dive .NET · Dec 1, 2024 · 9 min read
Most Clean Architecture articles stop at the circle diagram. The part that actually decides whether a team can live with the pattern is more mundane: which project does this class go in, which direction do the references point, and where do the interfaces live. I built the Contact Management Application as a .NET Core Web API to answer exactly those questions with running code, and this series walks through it layer by layer.
Clean Architecture: Introduction to the Project Structure

Best Practices for Creating and Using DTOs in the API

Deep Dive .NET · Dec 1, 2024 · 6 min read
Serializing domain entities straight to the client looks like a shortcut until the first schema change. Rename one property on the entity and every consumer of the API breaks with it, and you find out from their bug reports. DTOs are the cheap insurance against that: the entity can change shape freely because the contract the client sees is a separate class you control. This post covers the DTO conventions I use in the Contact Management Application and why each one exists.
Best Practices for Creating and Using DTOs in the API