Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Access Services in Class to be used as Singleton

$
0
0

I have a class that I am going to load as Singleton to store data for use across my Blazor web app.

My issues is that the class also requires services that I added.

Is it possible to instantiate a class as singleton and load the data with services I've implemented?

Some of the data to be loaded is retrieved with Async calls which is why I have the Initialize and not just using the constructor.

Below is what I currently have. If I need myAppData to access GraphServices, how do I do that while also loading myAppData as a service?

AppData myAppData = AppData.Initialize;builder.Services.AddTransient<IGraphServices, GraphServices>();builder.Services.AddSingleton(myAppData);

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>