Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Inconsistent naming of async methods #1009

Open
CniKKoR opened this issue Jan 29, 2024 · 1 comment · May be fixed by #1014
Open

Inconsistent naming of async methods #1009

CniKKoR opened this issue Jan 29, 2024 · 1 comment · May be fixed by #1014

Comments

@CniKKoR
Copy link

CniKKoR commented Jan 29, 2024

I know it's not an issue in general, but there is no consistent sceme of naming async methods, at least none I noticed.

Also all async methods should include the Async Suffix.

Source:
https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/task-asynchronous-programming-model#BKMK_HowtoWriteanAsyncMethod

The name of an async method, by convention, ends with an "Async" suffix.

for exmaple:

https://github.com/dotnet-architecture/eShopOnWeb/blob/main/src/Web/Pages/Shared/Components/BasketComponent/Basket.cs

public async Task<IViewComponentResult> InvokeAsync() {    ...    }

private async Task<int> CountTotalBasketItems() {    ...    }

private string? GetAnnonymousIdFromCookie() {    ...    }

For consistency CountTotalBasketItems() should also have the Suffix like InvokeAsync()

another example:

https://github.com/dotnet-architecture/eShopOnWeb/blob/main/src/Web/Pages/Admin/EditCatalogItem.cshtml.cs

public void OnGet(CatalogItemViewModel catalogModel) {    ...    }

public async Task<IActionResult> OnPostAsync() {    ...    }

All fine up here, BUT:

https://github.com/dotnet-architecture/eShopOnWeb/blob/main/src/Web/Pages/Basket/Index.cshtml.cs

public async Task OnGet() {    ...    }

public async Task<IActionResult> OnPost(CatalogItemViewModel productDetails) {    ...    }

public async Task OnPostUpdate(IEnumerable<BasketItemViewModel> items)  {    ...    }
@ardalis
Copy link
Collaborator

ardalis commented Jan 29, 2024

Probably we should update the editorconfig as this PR does:
ardalis/EditorConfig#2

@Kamyab7 Kamyab7 linked a pull request Feb 11, 2024 that will close this issue
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants