You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am familiar with writing highly responsive ASP.NET MVC applications where we load the initial page data, and then fire off multiple AJAX calls to load "secondary" data for the page. So behinds the scenes, these AJAX requests all hit the web server(s) about the same time and pull data from our SQL DB.
I envisage doing something very similar with a Blazor application. So, we'd load the page with some data and then have multiple components then display on the page with additional data; the loading of these components could be initialized by a user action, or by some other event(s) on the page.
And that's where I see a problem: the event handlers all react very nicely to events fired by the various components on the razor page, and they all then hit our DataService (injected into the page) which then results in lots of threads hitting our Entity Framework's Context.
And that's not allowed - only one thread may call the context at any one time.
To get around this, I can lock the Context using a SemaphoreSlip(1,1) to ensure that only one thread gets access at any one time, but that seems a bit of a bottle neck to me. Surely locking the Context is not something that Microsoft would be expecting us to do....??
So what am I missing here?
My setup
I'm using Blazor-Server, .NET Core 3.1/EF Core 3.1. In my App's startup, I'm setting up the EF Context and the Service for DI:
MyService has a bunch of async/awaited calls, each using the same context. Although MyContext is deliberately small, I can't see us wanting to instantiate it for every call, hence why it's using the constructor-injected instance.
Oh, and of course, the Service is injected into the *.razor page.
Original Comments
Visual Studio Feedback System on 11/4/2019, 10:38 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
The text was updated successfully, but these errors were encountered:
@DrGriff It works the same way. The issue was happening in a prerendering context in which the code runs on the server. Using OwningComponentBase<T> is still the answer.
ghost
locked as resolved and limited conversation to collaborators
Dec 14, 2019
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
This issue has been moved from a ticket on Developer Community.
I am familiar with writing highly responsive ASP.NET MVC applications where we load the initial page data, and then fire off multiple AJAX calls to load "secondary" data for the page. So behinds the scenes, these AJAX requests all hit the web server(s) about the same time and pull data from our SQL DB.
I envisage doing something very similar with a Blazor application. So, we'd load the page with some data and then have multiple components then display on the page with additional data; the loading of these components could be initialized by a user action, or by some other event(s) on the page.
And that's where I see a problem: the event handlers all react very nicely to events fired by the various components on the razor page, and they all then hit our DataService (injected into the page) which then results in lots of threads hitting our Entity Framework's Context.
And that's not allowed - only one thread may call the context at any one time.
To get around this, I can lock the Context using a SemaphoreSlip(1,1) to ensure that only one thread gets access at any one time, but that seems a bit of a bottle neck to me. Surely locking the Context is not something that Microsoft would be expecting us to do....??
So what am I missing here?
My setup
I'm using Blazor-Server, .NET Core 3.1/EF Core 3.1. In my App's startup, I'm setting up the EF Context and the Service for DI:
The Context is injected into the constructor of the Service:
MyService has a bunch of async/awaited calls, each using the same context. Although MyContext is deliberately small, I can't see us wanting to instantiate it for every call, hence why it's using the constructor-injected instance.
Oh, and of course, the Service is injected into the *.razor page.
Original Comments
Visual Studio Feedback System on 11/4/2019, 10:38 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
The text was updated successfully, but these errors were encountered: