I am planning to do an async/await in C# Blazor class constructor method. Although this is written in Blazor it's a generic for C# so it doesn't matter.
public class DoctorsService : IDoctorsService
{
private readonly IConfiguration _config;
public DoctorsService(IConfiguration config, IClinicsDoctorsService clinicsDoctorsService)
{
_config = config;
clinicsDoctorsService.GetClinicsDoctorsListAsync(new Dictionary<string, string>());
}
}
If you noticed the clinicsDoctorsService
isn't awaited using await
, that's bc the compiler will complain that the method must be in async Task
. If I write it like public async Task DoctorsService()
, the compiler will complain with another issue because you cannot name a method same with the class name.