• Stars
    star
    444
  • Rank 98,300 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Configure async code's ConfigureAwait at a global level

ConfigureAwait.Fody

Chat on Gitter NuGet Status

Configure async code's ConfigureAwait at a global level.

This is an add-in for Fody

It is expected that all developers using Fody become a Patron on OpenCollective. See Licensing/Patron FAQ for more information.

Usage

See also Fody usage.

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 code. 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

Explicitly configured awaiters will not be overwritten by the weaver, allowing exceptions to the Assembly / Class / Method level setting.

Add to FodyWeavers.xml

Add <ConfigureAwait/> to FodyWeavers.xml

<Weavers>
  <ConfigureAwait/>
</Weavers>

It is also possible set the default ContinueOnCapturedContext in the xml config:

<Weavers>
  <ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

Example

Before code

using Fody;

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

    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(true);
    }

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

Icon

Created by Dmitry Baranovskiy from The Noun Project.

More Repositories

1

Fody

Extensible tool for weaving .net assemblies
C#
4,325
star
2

Costura

Embed references as resources
C#
2,383
star
3

PropertyChanged

Injects INotifyPropertyChanged code into properties at compile time
C#
1,885
star
4

NullGuard

Adds null argument checks to an assembly
C#
686
star
5

MethodTimer

Injects some very basic method timing code.
C#
686
star
6

Home

The landing page for Fody repositories
C#
671
star
7

MethodDecorator

Compile time decorator pattern via IL rewriting
C#
380
star
8

Anotar

Simplifies logging through a static class and some IL manipulation.
C#
262
star
9

Equals

Generate Equals, GetHashCode and operators methods from properties.
C#
111
star
10

AsyncErrorHandler

An extension for Fody to integrate error handling into async and TPL code
C#
104
star
11

FodyAddinSamples

A working sample for each Fody Addin
C#
95
star
12

ToString

Generate ToString method from public properties.
C#
82
star
13

Janitor

Simplifies the implementation of IDisposable
C#
76
star
14

Ionad

Replaces static method calls.
C#
68
star
15

InfoOf

Provides methodof, propertyof and fieldof equivalents of typeof .
C#
65
star
16

Virtuosity

Change all members to virtual as part of your build.
C#
61
star
17

PropertyChanging

Injects INotifyPropertyChanging code into properties at compile time.
C#
54
star
18

ExtraConstraints

Facilitates adding constraints for Enum and Delegate to types and methods.
C#
47
star
19

Visualize

Adds debugger attributes to help visualize objects.
C#
43
star
20

Caseless

Change string comparisons to be case insensitive.
C#
40
star
21

Resourcer

Simplifies reading embedded resources from an Assembly.
C#
37
star
22

LoadAssembliesOnStartup

Loads all the references on startup by actually using the types in the module initializer.
C#
36
star
23

Obsolete

Helps keep usages of ObsoleteAttribute consistent.
C#
32
star
24

EmptyConstructor

Adds an empty constructor to classes even if you have a non-empty one defined.
C#
29
star
25

Scalpel

Strips all testing code from an assembly
C#
27
star
26

AssertMessage

Add 'message' parameter to Assertions. Nunit, Mstest, Xunit is supported.
C#
22
star
27

Publicize

Converts non-public members to public hidden members
C#
12
star
28

UniversalAppSample

C#
7
star
29

.github

1
star