In a .net core application, I have an ISessionService (it just contains various reusable properties, like the current "Company" based on what the currently URL is.
It is defined in startup like this:
services.AddScoped<ISessionService, SessionService>();
SessionService has a property that is .Company. But in .Company a call is made to the database which, because it's a property, can't be awaited. So it currently looks like
public ICompany Company => dbContext.GetCompany(host).Result
The .Result is causing application hangs under heavy load. I could put this in the constructor of SessionService, but that just moves the .Result from the property to the constructor and causes the same problem.
Is there a way, through the initialisation of SessionService perhaps, to initialise in an async way without having to do any synchronous calls like .Result?