Vaughan

Consuming paged Twitter data with async enumerable

.NET Core

A really nice feature in C# 8 is async enumerables. A popular use case is if you want to consume paged data and potentially aggregate each page of data without having to get everything first. Previously the consuming code would have to handle the paging but now your method can just enumerate over the IAsyncEnumerable […]

Read more
Vaughan

Creating an AWS Lambda function written in C# .NET Core

.NET Core, AWS

With more and more companies moving to the cloud, the idea of serverless execution of your code has more and more appeal. AWS has Lambda and Azure has Functions. The idea is the same: You give them a method that you want to execute and the provider works out the scaling. As you get more […]

Read more
Vaughan

ASP.NET Core integration tests with WebApplicationFactory

.NET Core, Testing

We all agree that we want to have tests that cover as much of our application as possible. Right? The general approach with ASP.NET applications has been to extract meaningful business logic out of your controllers. Pretty much everything that needs to be tested would be injected with an interface so that its easy to […]

Read more
Vaughan

Performance with ref readonly returns

.NET Core

When looking at performance of an application, there is a trade off between when you should be using value types and when you should be using reference types. People often talk about minimizing allocations to the heap for reference types but allocations themselves are actually very quick. The reason why its an issue is that […]

Read more
Vaughan

Understanding default interface members in .NET Core

.NET Core

A new feature in C# 8.0 and .NET Core 3.0 is that of default interface members. The motivation for it is where authors of a public interface would like to add functionality to an existing interface but don’t want to force all the consuming code to implement it. You are able to add a default […]

Read more
Vaughan

Using the new Index and range operators

.NET Core

A great C# feature that was recently released is the new Index and Range operators. Two new system objects were created to make accessing elements or range of elements in arrays shorter and more convenient. Index You can now index an array from the end of the array instead of using Array.Length. To be honest, […]

Read more
Vaughan

A case for pattern matching

.NET Core

Over the years developers using more functional languages like F# have boasted about how much easier their code is to read and how imperative C# can be. NO LONGER! Well maybe not much longer. We are starting to move in the right direction with pattern matching as a good replacement for switch statements. switch statements […]

Read more
Vaughan

Why is async void return bad?

.NET Core

When writing async code, your method is allowed to return either void, Task, Task, or ValueTask). Since early on with async code, the advice has been to not use void return methods. But in real life there are times when you don’t really have a choice. Since we can’t always get away from using them, […]

Read more
Vaughan

Running a .NET Core HostedService as a Windows service

.NET Core

If you need to run your long running .NET Core worker application on a windows server, you can easily install it as a windows service with minimal changes. Just add the following package. Microsoft.Extensions.Hosting.WindowsServices Then all you have to do is add UseWindowsService() to your host builder and its ready to use. public static IHostBuilder […]

Read more
Vaughan

When to consider using ValueTask over Task with async code

.NET Core, BenchmarkDotNet, Benchmarking, Measuring, Performance

As of .NET Core 2.0, you can use ValueTask and ValueTask as return types for your async methods. Its important to understand when and if you should use these instead of a Task and what the trade-offs are if you decide to use it. I would say that if you aren’t measuring the performance of […]

Read more

BMC logoBuy me a coffee