Software Development

How to use Minimal APIs in .NET 8 without cluttering Program.cs

Minimal APIs were first introduced in ASP.NET Core 6.0 and have been around for some time now. At a high level, Minimal APIs are a simplified way of building HTTP APIs with ASP.NET Core.

But why use Minimal APIs over the classic MVC / Controller workflow that we’re all familiar with?

  • ASP.NET MVC is useful if you want to organise your code based on layers. Minimal APIs are useful if you would rather organise your code by features/slice, keeping related things together… but you can still keep a layered architecture with Minimal APIs if you prefer.
  • MVC is opt-out, running an entire filter pipeline for each request, even if you don’t actually need all of it. When using Minimal APIs, you need to explicitly opt-in to validation, model binding, and any filters that you’d like to run on each request. Minimal API filters are also simpler, with the capability to do everything that MVC can.
  • ASP.NET MVC’s convention based model can be difficult to understand and debug - it isn’t always clear exactly which routes would be discovered and configured via reflection, and getting this right can be error-prone especially early in the project. With Minimal API, routes are explicitly mapped, making Minimal API routes easier to understand and debug.
  • Controllers can be harder to test, and tend to grow in complexity over time - I’ve seen controllers become a massive file with a equally massive constructor (upwards of 20 parameters); you’ll need to inject all those parameters when instantiating the class in a unit test, even if method you’re testing only uses one of those parameters…. leading to controllers sometimes not having test coverage.
  • ASP.NET Core is moving toward native AOT compilation, which is not compatible with ASP.NET MVC.

Read on to find out how mitigate the most common concerns with adopting Minimal APIs.

Continue Reading...

Ten programming books that can be read passively

We’ve all got busy lives, and it can sometimes be difficult to find time to sit down and read a chunky and dense programming book. (I’m looking at you, SICP!!)

A reader recently asked which programing books can be more casually read, without having to commit to a long reading session.

Here are ten of my favorites:

Continue Reading...

Top useEffect mistakes made by React Developers

useEffect is a kind of “escape hatch” which lets you perform side effects in functional components.

Effects let you step outside of React, giving you the ability to synchronise your components with systems that aren’t controlled by React such as a non-react widget, an external system (such as a browser API), a third party library, or a network connection.

Effects aren’t always necessary; if there is no external system involved, you shouldn’t need useEffect.

But it isn’t always clear when effects are necessary, and how to use them. Which leads to some common mistakes.

Here are some of the top mistakes that I’ve seen people make with useEffect:

Continue Reading...

Using Docker for local web development

If you’re new to Docker, it’s hard figuring out even what to search for, and how the concepts tie together, let alone what to pay attention to for your use case.

To make things more difficult, there has been a lot of change over time, and stuff that was once recommended is now not recommended. For example, a lot of older video tutorials recommend using container links which have since been deprecated in favor of user-defined bridge networks .. in case you’re unfamiliar with this, I’ll cover what this means, and why you’d use it later in the blog post.

Once you learn the basics, using Docker in practice is fairly straightforward, and if you’re using Docker at home or at work, the time you spend learning now will save you a massive amount of time and effort in the future.

If you’ve used Docker a bit, are familiar with some of the concepts, how dabbled here and there, but sometimes struggle with connecting some of the concepts, or how to get things set up end-to-end, then this blog post is for you.

In this blog post, I’ll guide you through step by step on:

  • The distinction between docker image and containers
  • Best practices on how to persist data within containers, and how to control where data is persisted
  • How to continue developing on your local machine as usual, while your app is running within a docker container on your local machine
  • How to connect your containerised web app to a containerised Microsoft SQL Server
Continue Reading...

Redux made easy with Redux Toolkit and Typescript

Using Redux with React can be incredibly challenging for people to get their head around; while the core principles of Redux itself are fairly straightforward and don’t take too long to grasp, a lot of people struggle with using Redux in React apps. Partly because there are so many damn things to integrate:

  1. Redux
  2. React Redux
  3. Redux Thunk
  4. Typescript (getting more common in recent years)
  5. Redux Saga / Redux Observable (in more complex apps)

I spotted this quote which summed it up for me:

Redux was such a mental overhead for me when I started out with it. The amount of boilerplate code that I had to write for the project I worked on was very frustrating.

I struggled with that stuff too, even after I became familiar with the concepts, I often found it difficult to understand the flow of data and events within React Redux apps. This is not uncommon, even the original author of Redux had this to say:

Yup. Can totally relate.

Then I found Redux Toolkit, written by the maintainers of Redux, and recommended by the Redux style guide.

Continue Reading...

How to scrape stock upgrades and downgrades from Yahoo Finance

In this blog post I’ll show you how to scrape stock upgrade and downgrade data from Yahoo Finance using Python, Beautiful Soup, json, and a bit of regular expression magic.

This technique can be applied to any stock symbol on Yahoo Finance, but for this blog post we’ll be scraping data for Apple (AAPL).

I’ll be guiding you through the process, describing my thought processes and techiques, and if you follow along, by the end of this blog post, you’ll have extracted stock upgrade and downgrade data in a Pandas dataframe which will look something like this:

From there, you can easily export the data into an Excel file, or if you’re a more advanced Python user, host the code in a Web API which can be accessed by Google Sheets, or your own custom code.

Continue Reading...

Accelerate - Building and Scaling High Performing Technology Organisations

I first read Accelerate by Nicole Forsgren, Jez Humble, Gene Kim back in 2018 when it was a hot topic in the office; only an hour or two would go by between overhearing somebody talk about it, internal blog posts were being written, and we’d receive emails about following the findings.

One of the goals behind the book was to run a series of surveys, gathering 23000 responses across 2000 organizations, then using statistical methods on the results in order to find a way to measure software delivery performance, and to find out what drives it. One of the most impressive things about the book is that it not only presents the research findings, but also goes into detail about why the findings are trustworthy, meaning that they not only tell us what they learned, but how they learned it.

I recently read through the book again and took a bunch of notes which cover the main points.

Continue Reading...

13 years ago we were rallying against nested HTML tables - Notes from Webstock 2019

I’m not sure why it’s taken so long, but after 13 years of Webstock existing, this year was the first time that I attended.

While I haven’t attended Webstock until now, I have watched many of the recordings which are usually available a few months after each event was held, and it’s been interesting to see how the event, and the industry in general has changed over the years.

None of this year’s talks were technical, and all were about the human side of the industry - topics such as ethics, personal experiences, psychology, communication, and team health.

One of the original organisers stood up on stage at the end of the event, and said it best:

13 years ago we were rallying against nested HTML tables

Continue Reading...