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

How to get an existing scoped instance of a Blazor App with BlazorWebView?

$
0
0

I have a Blazor App, which creates an instance of "MyClass" through serviceCollection.AddScoped(). Within my Blazor App I can inject this instance.

But now I want to access this instance from my BlazorWebView (e.g. in MAUI, WPF, WinForms, etc.).

serviceCollection.AddScoped<MyClass>();...blazorWebView.Services.GetService<MyClass>();  // returns a new instance instead existing one

If I use "AddSingleton()" it is working of course, but how do I get the scoped instance of MyClass created by my Blazor App?

Expected result: The already created instance from Blazor App


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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