Is it necessary to await every time I use something async or can I await it once after multiple async methods?
Can I skip using await
in the repository since I'm awaiting in the consumer?
public class SomethingRepository : ISomethingRepository
{
private readonly DbSet<Something> _dbSet;
public SomethingRepostory(ApplicationContext ctx)
{
_dbSet = ctx.Set<Listing>();
}
// Should it be like variant 1?
public Task<List<Something>> GetAsyncVariant1()
{
return _dbSet.ToListAsync();
}
// Or like variant 2 with async/await?
public async Task<List<Something>> GetAsyncVariant2()
{
return await _dbSet.ToListAsync();
}
}
// Usage in consumer
var data = await _somethingRepository.GetAsync();