Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Combine Blazor and Web API in same project with Entity Framework

$
0
0

I have a Web API project (dotnet8) which hosts some API endpoints. Those endpoints use services which hold all the business logic, where the services use EF's DbContext to communicate with the database.

Now I want to add a Blazor (server) frontend to the application, to include a simple GUI. All tutorials mention that when using Blazor server, you should use EF in another way to prevent memory leaks and weird database behaviour. It is recommended to use EF with a DbContext factory and instantiate a DbContext everytime it is needed. This is all because scopes mean something different in a Blazor circuit then in an http pipeline.

This all seems very logical to me, but I still cannot seem to reason how to approach this with a hybrid solution;

How should I use/configure Entity Framework when the DbContext is used in services, that are used in both Web API (request scoped) and in Blazor components (circuit scoped)?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>