samples
samples copied to clipboard
Incorrect service lifetime
This sample will probably be ported to Razor Components in the near future. You should change service lifetime to scoped. Otherwise state will be shared between all users which is not what you want.
https://github.com/aspnet/samples/blob/136b4bb35ba8001b230bd21c8ac632c4b572bb41/samples/aspnetcore/blazor/FlightFinder/FlightFinder.Client/Startup.cs#L11
Keep in mind that the Razor application is executed inside the client browser, so every user will have his own singleton object (i.e., it acts like a client application).
@marcominerva My first sentence was:
This sample will probably be ported to Razor Components in the near future.
Current name for Razor Components is Blazor Server Side. In this model application is executed on the server. On the client singleton and scoped works the same. If you want to have an application that works correctly in server and client mode you should use scoped for services which have to be unique for each user.
Ok, got it. In your first comment you quoted a FlightFinder.Client project file, so I thought you were referring only to the client side.
@SteveSandersonMS @danroth27