Just pass preallocated object
var api = new ApiClient();
api.LoadCache();
builder.Services.AddSingleton<ApiClient>(api);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How do i call this 'LoadCashe' method from my service?
My goal is to load a cashe, before the razor pages run. The cashe should never be null. Its on WebAssembly, if that might matter.
[ what i have tried ]
i have heard about factory methods.
i have seen this: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-5.0 (see Call services From Main) But, i do not see similarities between this version of program.cs and mine. Plus i do not understand the example enough to make sure i do it as robustly as intended.
Just pass preallocated object
var api = new ApiClient();
api.LoadCache();
builder.Services.AddSingleton<ApiClient>(api);