Reputation: 1
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)?
Upvotes: 0
Views: 2051
Reputation: 143373
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.
Upvotes: 1