Professional Development – 2024 – Week 45

Image Credit: https://www.flickr.com/photos/54585499@N04/

.NET

Stop Using AutoMapper in .NET (via Nick Chapsas)

The primary argument is that if things aren’t set up correctly, you don’t know at compile time. Unit tests should never mock the AutoMapper; use the real mapper. Mapperly is an alternative that uses compile-time mapping. To do it manually, you can make extension methods that map from one class to another. Sometimes simpler is better rather than being too clever with tooling.

The Right Way To Return API Errors in .NET (via Nick Chapsas)

  • This approach implements RFC 9457 (Problem Details for HTTP APIs).
  • .NET provides a Results.Problem(type, title, detail, statusCode) method.
  • You can expand it using builder.Services.AddProblemDetails() to understand which request instance caused the problem as well as its trace identifier.
  • The video also covers (although not ideal) a global problem exception handler. (This seemed fairly complex.)