For an ASP.NET MVC application I'm wondering how much is too much. Here's some example code that I've tried to make as async as possible.
For MVC, at what point is async not doing us any favors?
Drilling down from the Controller action:
publicasync Task<ActionResult> DetailsAsync(int id)
{
ViewData.Model = await ProjectEdit.GetProjectAsync(id);return View();
}
CSLA business object and DAL:
publicstaticasync Task<ProjectEdit> GetProjectAsync(int id)
{returnawait DataPortal.FetchAsync<ProjectEdit>(id);
}privateasync Task DataPortal_FetchAsync(int id)
{using (var ctx = ProjectTracker.Dal.DalFactory.GetManager())
{var dal = ctx.GetProvider<ProjectTracker.Dal.IProjectDal>();var data = await dal.FetchAsync(id);using (BypassPropertyChecks)
{
id = data.Id;//....
}
}
}publicasync Task<ProjectDto> FetchAsync(int id)
{using (var ctx = ObjectContextManager<PTrackerEntities>.GetManager("PTrackerEntities"))
{var result = from r in ctx.ObjectContext.Projects
where r.ProjectId == id
select new ProjectDto
{
ProjectId = r.ProjectId
};returnawait result.FirstAsync();
}
}