Scope of session in Blazor Server-side

38 views
Skip to first unread message

Ivan Montilla

unread,
Jan 24, 2020, 7:58:04 AM1/24/20
to RavenDB - 2nd generation document database
Hello,

In Blazor Server-side, the scope of a service is the SignalR connection between the browser and the server. More info: https://chrissainty.com/service-lifetimes-in-blazor/

Assume that I'm registering the session at scope:

services.AddScoped(_ => documentStore.OpenAsyncSession());

Imagine I open my app, then I navigate to a page that show a list of customer, the session query the server and get this list, then I navigate to a customer profile, because I'm in the same SignalR connection, the same session instance is used to query the customer profile.

The RavenDB docs says that a session has a maximun number of server request and the ideal is 1 https://ravendb.net/docs/article-page/4.2/csharp/client-api/session/configuration/how-to-change-maximum-number-of-requests-per-session

In MVC/Razor pages app, this can be achive easy because a session is scoped per HTTP Request, but in Blazor app I'm not sure how I shlould to register the session. (Maybe transient?)

Note: I never changed the maximun number of request, but the session seems working after navigating more that 30 times between two pages in the same connection (and same scoped).

Oren Eini (Ayende Rahien)

unread,
Jan 27, 2020, 10:49:49 AM1/27/20
to ravendb
A connection is long lived. A user may have a connection open for a _long_ time and have many interactions with it.
That would raise the error on max number of operations, but that isn't the problem. All the entities the session have touched are held by it, in memory.
That is probably no something you want.
In server side Blazor, go ahead and use transient, yes.

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/c7e43d7d-81a5-44d9-9ad9-0332ced1d932%40googlegroups.com.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
Reply all
Reply to author
Forward
0 new messages