Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityFrameworkCore - Blazor Server Guidance #280

Closed
jlipford opened this issue Jul 22, 2022 · 2 comments
Closed

EntityFrameworkCore - Blazor Server Guidance #280

jlipford opened this issue Jul 22, 2022 · 2 comments

Comments

@jlipford
Copy link

jlipford commented Jul 22, 2022

Any opinions on the use of this library and the abstract (included) repository for use with Blazor Server given this guidance? https://docs.microsoft.com/en-us/aspnet/core/blazor/blazor-server-ef-core?view=aspnetcore-6.0

Using DBContextFactory vs direct DbContext and the lifetime of those objects and thread safety?
Can a version of the included RepositoryBase (for EntityFrameworkCore) implementing disposable be provided? Or expose the underyling context as protected instead of private?

Maybe I am overthinking it but worried about thread safety using circuits but I love this library!
Great work as usual @ardalis !!!

@jasonsummers
Copy link
Contributor

Hi @jlipford,

I've coincidentally been working on this in another project this week. I think it's a fairly niche use case but I've submitted my code as a pull request should you wish to use it either verbatim or for inspiration.

Essentially it boiled down to two options for me:

  1. Create a factory for repositories, so instead of using IDbContextFactory you'd use IRepositoryFactory; or
  2. Hide the fact that DbContextFactories were being used at all and do all of the magic behind the IRepository interface

I opted for the latter for a number of reasons, chief amongst which was that, should I choose to swap out my EntityFramework based repositories for say DAPPER ones, it shouldn't affect consumers of the IRepository interface. The downside of this approach (or at least my implementation of it) is that you lose Entity Framework's change tracking magic. For me, this isn't a problem since I manage all my entity state in the Domain Layer and treat all of my objects as disconnected anyway here's a really good article that goes into more detail.

Hope some of this is useful to you. Very interested to hear the opinions of others, especially if they differ from mine.

@ardalis
Copy link
Owner

ardalis commented Mar 9, 2023

Closing as inactive.

@ardalis ardalis closed this as completed Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants