A Fody Addin
Clone or download

readme.md

Icon

This is an add-in for Fody

Allows you to set your async code's ConfigureAwait at a global level.

NuGet package

Install the ConfigureAwait.Fody NuGet package and update the Fody NuGet package:

PM> Install-Package Fody
PM> Install-Package ConfigureAwait.Fody

The Install-Package Fody is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.

How to use it

By default, ConfigureAwait.Fody doesn't change any of your code. You have to explicitly set a configure await value at the assembly, class, or method level.

  • [assembly: Fody.ConfigureAwait(false)] - Assembly level
  • [Fody.ConfigureAwait(false)] - Class or method level

Add to FodyWeavers.xml

Add <ConfigureAwait/> to FodyWeavers.xml

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <ConfigureAwait/>
</Weavers>

Example

Your code

using Fody;

[ConfigureAwait(false)]
public class MyAsyncLibrary
{
    public async Task MyMethodAsync()
    {
        await Task.Delay(10);
        await Task.Delay(20);
    }

    public async Task AnotherMethodAsync()
    {
        await Task.Delay(30);
    }
}

What gets compiled

public class MyAsyncLibrary
{
    public async Task MyMethodAsync()
    {
        await Task.Delay(10).ConfigureAwait(false);
        await Task.Delay(20).ConfigureAwait(false);
    }

    public async Task AnotherMethodAsync()
    {
        await Task.Delay(30).ConfigureAwait(false);
    }
}

Icon

Created by Dmitry Baranovskiy from the Noun Project.