Archive for the .NET Core category

Vaughan

Why you should use the IHttpClientFactory in ASP.NET Core

.NET Core

One surprising issue when using the HttpClient, is the issue of port exhaustion. This often happens when an application creates a lot of HttpClient instances for short requests. When there is sufficient load the machine may run out of tcp ports and then it won\’t be able to make another request until a port opens […]

Read more
Vaughan

Using automapper in ASP.NET Core

.NET Core, Automapper

To be honest I have mixed feelings on using something like automapper by default but there are definitely cases when it heavily reduces the amount of code you write and therefore your bugs. It has pretty good integration with ASP.NET Core so when it should be used, it won\’t take long to get started. To […]

Read more
Vaughan

ASP.NET Core: Injecting dependencies directly into controller actions

.NET Core

One feature in ASP.NET Core that I was surprised by is the ability to inject a service into a specific action of a controller. Normally you inject into a constructor of a controller and keep the dependencies as local variables. So imagine a controller like this: [Route(api/[controller])] [ApiController] public class PersonController : ControllerBase { private […]

Read more
Vaughan

ASP.NET Core: Using fluent validations in your api controllers

.NET Core

If you need to validate the inputs to your api actions I really do recommend trying the FluentValidation.AspNetCore package. Its very easy to integrate and you can do quite powerful validations. As an example I created a Person controller. [Route(api/[controller])] [ApiController] public class PersonController : ControllerBase { [HttpPost] public async Task<ActionResult> Post([FromBody] PersonViewModel person) { […]

Read more
Vaughan

Semantic logging with ASP.NET Core

.NET Core

One subtle adjustment that some of the older .net developers most probably need to make is that idea of semantic logging in ASP.NET core. This is subtle because a lot of us started used string interpolation a few years ago. The examples in the documentation look very similar to how my string interpolation strings look. […]

Read more
Vaughan

ASP.NET Core IOptions Validation

.NET Core

I\’ve spoken previously about IOptions in ASP.NET core. On their own, they are a very useful way to inject configuration into your services. What I didn\’t mention is that they allow you to build in validation of your configuration. One reason that this might be needed is that the IOptions services are normally very forgiving […]

Read more
Vaughan

ASP.NET Core dependency injection: Registering open generics

.NET Core

A really interesting trick you can do with the ASP.NET core dependency injection is that you can register an open generic type. The prime example is the ILogger interface that is built in. Each class can inject a ILogger of its type without having to register it specifically. It can be quite a powerful technique […]

Read more
Vaughan

ASP.Net Core Hosted services

.NET Core

In the containerized application and Kubernetes world, quite often you need to create services that aren\’t traditional rest endpoints. Your application could for example rather listen to a message queue to process requests. It would be nice to still have all the nice infrastructure of .NET Core applications and things like health checks but have […]

Read more
Vaughan

ASP.NET Core configuration in Docker containers

.NET Core, Docker

In the old days of .NET applications we had a simple xml configuration file that would ship with each environment. This was tried and tested and was well understood. Then came Docker. The promise was that I could build a container on my machine and then ship that exact container to production. This is great […]

Read more
Vaughan

ASP.NET Core with IOptions

.NET Core

One of my favorite improvements when moving to ASP.NET Core applications is that configuration feels like a first class citizen in the infrastructure. Previously I often had to do some manual work in the DI registration to create configuration objects that could be injected into my classes. No longer! ASP.NET Core uses the options pattern […]

Read more

BMC logoBuy me a coffee