I'm using c# .net core 5 Blazer WebService.
I have a service that has a list of Thing as a property.
public class Service : IService
{
public HashSet<Thing> Things {get; set;}
}
Now I want to load the Things from disk, so I cache them privately in the service
public class Service : IService
{
private HashSet<Thing> _things
public HashSet<Thing> Things => _things : LoadThings();
}
But LoadThings() accesses the disk so I want that IO to run asynchronously and await it. But now LoadThings() needs to be async, and I can't do:
public class Service : IService
{
private HashSet<Thing> _things
public HashSet<Thing> Things => _things : await LoadThings();
}
And I get why; the async chain is lost.
So my question is this: What's the best way to get _things but await an async IO if _things is null?