samples icon indicating copy to clipboard operation
samples copied to clipboard

Incorrect service lifetime

Open Andrzej-W opened this issue 6 years ago • 4 comments
trafficstars

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

Andrzej-W avatar Feb 16 '19 20:02 Andrzej-W

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 avatar May 04 '19 16:05 marcominerva

@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.

Andrzej-W avatar May 05 '19 21:05 Andrzej-W

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.

marcominerva avatar May 05 '19 21:05 marcominerva

@SteveSandersonMS @danroth27

Eilon avatar May 29 '19 05:05 Eilon