I'm trying to write a simple web api service with Users CRUD, i'm a bit confused about using async/await methods in repository pattern... pattern flow is: CONTROLLER > BLOGIC > REPOSITORY where i must use async/await methods ? in all layers or only at the top (controller layer)?
Asked
Active
Viewed 1,291 times
0
-
Async needs to be used all the way down. A synchronous method at any level will introduce a block, which defeats the purpose of async. – Johnathan Barclay May 29 '20 at 09:58
-
1Please add more detailed indormation in your question and add code sample you tried. – May 29 '20 at 09:59
-
Does this answer your question? [Architecture for async/await](https://stackoverflow.com/questions/15503782/architecture-for-async-await) – Guru Stron May 29 '20 at 10:04
1 Answers
1
async
is "bubbling" up in your code structure, so obviously main source of asynchronous code should be your repository layer, but to leverage it being asynchronous you will need to make all calling code to be asynchronous too (or just return Task<T>
if caller just passes results without doing anything with them) otherwise you will need to block on asynchronous call which basically not only removes all possible gains from it but also in some cases can introduce issues.
Also please read this answer.

Guru Stron
- 102,774
- 10
- 95
- 132