December 2019
Intermediate to advanced
510 pages
11h 33m
English
When we implement code in an asynchronous way we should ask ourselves if the underlying process involves any kind of I/O operation. If this is the case, we should proceed by using an asynchronous approach for that stack. For example, the Get operation of the ItemRepository class involves a query to the database:
namespace Catalog.Infrastructure.Repositories{ public class ItemRepository : IItemRepository { .. public async Task<Item> GetAsync(Guid id) { var item = await _context.Items .AsNoTracking() .Where(x => x.Id == id) .Include(x => x.Genre) .Include(x => x.Artist).FirstOrDefaultAsync(); return item; } ... }}
In this case, we are using the FirstOrDefaultAsync method to execute the operation in ...