...
/Implementing an Asynchronous Controller Action Method
Implementing an Asynchronous Controller Action Method
Learn to implement an asynchronous controller action method.
We'll cover the following...
Steps to implement an asynchronous controller action method
Now, we are going to change the implementation of the unanswered questions endpoint so that it's asynchronous:
We are going to start by creating an asynchronous version of the data repository method that gets unanswered questions. So, let's create a new method in the data repository interface underneath
GetUnansweredQuestions
inIDataRepository.cs
:
Press + to interact
public interface IDataRepository{...IEnumerable<QuestionGetManyResponse>GetUnansweredQuestions();Task<IEnumerable<QuestionGetManyResponse>>GetUnansweredQuestionsAsync();...}
The key difference with an asynchronous method is that it returns a Task of the type that will eventually be returned.