I use core 6 and initiate a class named DAL as a scoped service in blazor server app.
Instead of creating new DAL instance to each connected device it uses the same instance to all of the devices.
I tested it in debug mode and it actually hit the services.AddScoped<DAL>(); line only once.
Any ideas ? Thanks
Startup.cs
[Obsolete]
public void ConfigureServices(IServiceCollection services)
{
//This command is for API route
services.AddMvc(setupAction: Options => Options.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddSingleton<HttpClient>();
services.AddScoped<DAL>();
services.AddBlazoredSessionStorage();
}
_Host.cshtml
<app>
<component type="typeof(App)" render-mode="Server" />
</app>
As per @enet's comments - I don't believe this.
The simplest way of testing this is is to assign a GUID to each instance of
DAL.Here's my Blazor Server version.
As expected I get a new Id for each browser window opened, which is the same as each device!