dotnet(3/0)
Dotnet snippets in justfile
In a recent project there were a few dotnet and Docker snippets that I wrapped into Justfile commands which saved me many headaches. ℹ️ All of these commands are executed in PowerShell. You'll need to add this line to the top of your Justfile for it to use PowerShell as its default interpreter. set windows-powershell := true The first runs the project locally. Nothing special. But it also runs a pre-requisite check function which ensures that another service that my project depends on is running.…
Slim your dotnet dockerfile
After discovering ways to shrink your python dockerfile, I immediately cringed when I saw my baseline dotnet Docker image was about 200MB. How can this be slimmed? Thanks to Brandon Atkinson for the ideas. The base Microsoft runtime image is a startling 190MB, so the first thing we’ll need to do is replace this image with something a bit more slim. Alpine Linux anyone? Let’s look at the minimum setup you’ll need to produce a single executable for an Alpine distro.…
Test a dotnet web service
Here are the basic steps to configure a service that uses HttpClient to make HTTP calls which can be unit tested. ⚠️ This was developed for a dotnet 7 console app. You may find that your code is more/less verbose. The Service Under Test First, here’s a basic template for a dependency-injected service. You can use these examples to refactor an existing service to inject an IHttpClientFactory so we have an interface to mock in our tests.…