Is it worth to create configurations for dbcontext?
I have following dbcontext:
I think context doesn't look good that is why I decided to use configurations
Example of configuration:
is it worth it? what is the best practice for such things?
4 Replies
At some point I don't think that there's a way around it.
Unless you want you DBContext class to get enormous.
if I'll use configurations then where DbSet properties should be placed?
dbcontext right now:
I think those should stay on the DBcontext.
If I were you, I would organize as follows.
A single file
Resource.cs
in YourProject.Models.Resources
folder structure.
As file scoped namespace cannot be combined with normal namespaces, we have 2 options:
- if we want to use just a single file then use normal namespace as mention above. (prefer for the sake of simplicity)
- if we want to separate the partial ReadModelDbContext
from the remaining one, use either normal namespace or file-scoped namespace.
Warning: partial classes cannot work as expected if they are in different namespaces. Because they are considered different types even though their names are identical.
The main ReadModelDbContext.cs
is saved usually in YourProject.Infrastructure.Commons
folder structure.