Friday, October 9, 2020

GraphQL Altair–Test and debug your GraphQL queries

As the GraphQL ecosystem keeps growing I’m continually founding new tools that make my job as a GraphQL developer easier. Recently I started using Altair, a GraphQL client application that makes it easy to test your GraphQL endpoints.

A selection of the features it has to offer:

  • Multi language/platform/window
  • Import and export queries
  • File upload
  • Syntax and query highlighting
  • Autofill all fields

Thursday, October 8, 2020

Quick tip if you want to play around with C# 9

The easiest way to start playing with C# 9 is by installing LinqPad 6. This allows you to play with the new language features without installing any extra dependencies.

To enable the new language features, go to Edit –> Preferences.

Go to the Query tab and set a checkbox next to Enable C# 9 preview features:

Wednesday, October 7, 2020

C#9- Record types

One of the most anticipated features coming in C#9 are Record types. Record types make it easy to create immutable reference types in .NET. They become the perfect fit for Value Objects in DDD terms.

A new keyword is introduced to support this: record. The record keyword makes an object immutable and behave like a value type.

An example:

You can even write this using a shorter syntax using positional records:

But what if you want to change the person name? How can we do this knowing that the object is immutable? Do I need to copy all properties into a new object?

Let’s introduce the with keyword to fix this. It allows you create an object from another by specifying what property changes:

Tuesday, October 6, 2020

C#9–Covariant return types

C# 9 adds a whole list of new language features. Most people talk about the support for record types and improved pattern matching but one of the features I’m happy that is finally added to the language are covariant return types.

You are probably asking covariant return what?????

Let’s explain; with return type covariance, you can override a base class method that has a less-specific type with one that returns a more specific type.

An example, before C#9 you would have to return the base type from the inherited class:

In C# 9, you can do the following:

Monday, October 5, 2020

RabbitMQ–Lazy queues

By default RabbitMQ tries to keep your whole queue in memory. This is OK as long as your messages are processed fast enough but not if your queue becomes very long(many millions of messages). Queues can become very long for various reasons:

  • consumers are offline / have crashed / are down for maintenance
  • there is a sudden message ingress spike, producers are outpacing consumers
  • consumers are slower than normal

Lazy Queues can help in these situations- messaged are moved to disk as early as practically possible, and are only loaded in RAM when requested by consumers.This comes at a cost of increased disk I/O.

You can configure this in MassTransit when configuring your receive endpoint:

More information: https://www.rabbitmq.com/lazy-queues.html

Friday, October 2, 2020

Database profiling in Visual Studio

Visual Studio 2019 version 16.3 extends the Performance Profiler with a new ‘Database’ option.  This will enable the new Database tool that captures all database activity during your profiling session.

Remark: The database tool works with .NET Core projects  using either ADO.NET or Entity Framework Core. It also works on traces collected using dotnet trace which means we can collect data anywhere that .NET Core runs (including Linux!) and analyze that data in Visual Studio.

Let’s try it:

  • Open the Performance Profiler in Visual Studio by clicking Debug > Performance Profiler.
  • Select the checkbox next to “Database” to enable the tool.

  • Click on Start to start the profiling session. Now interact with your application in the ways you’re interested in investigating. When you are done click ‘Stop collection’.

  • Now you get a table of all the queries that happened during your profiling session along with a graph that shows when and how many queries happen over time.

  • After identifying a query that warrants further investigation, you can go to the related code by right-clicking on a row, and selecting “Go To Source File”!

Thursday, October 1, 2020

Improve the startup time of your .NET Core application

Starting from .NET Core 3.x tiered compilation is enabled by default. This allows you to use precompiled code from assemblies created using the ReadyRoRun(R2R format. R2R is a form of ahead-of-time (AOT) compilation.

It improves startup performance by reducing the amount of work the just-in-time (JIT) compiler needs to do as your application loads.

To use this feature you need to enable ReadyToRun and publish your application as a self-contained app.

  1. Add the <PublishReadyToRun> setting to your project:

    <PropertyGroup>  
       <PublishReadyToRun>true</PublishReadyToRun>
    </PropertyGroup>

  2. Publish a self-contained app. Here is an example targetting the Linux ARM64 runtime:

    dotnet publish -c Release –r linux-arm64 --self-contained