Background

This post is about taking a functional approach to dependency injection using an ASP.NET core application written in F# as an example.

Lets say that we are are building an ASP.NET Core web application that exposes an HTTP API, and we want to automatically test the whole application pipeline.

As we only want to test the application behavior we need to be able to identify and isolate any external dependencies. With that done, we will also be able to replace those with fake implementations when running tests. This way we can focus on testing the application behavior without worrying about any external components.

Next up I will be showing an example of how to use dependency injection and partial application to achieve this.

Example case

The application we are building is a service that takes in a URL that points to a text document and shows the contents of that document in uppercase text. The interface to our application is an URL that accepts HTTP GET request and this interface is also used in tests.