Mitchelln11
Active member
- Joined
- Apr 10, 2020
- Messages
- 39
- Programming Experience
- Beginner
I am updating my .NET Core web app from just MVC to a Service-Repository pattern.
My question is, how do you implement DbSet<> when you add the Service and Repository layers?
I originally added these to my ApplicationDbContext file under the Data folder. Is this still correct? Then would I just use DI to call my database on each repository?
Or do I have my own DbContext for each table? (Where would DbSet<> go then?)
If I am completely off-base here, or talking nonsense, please let me know.
Thanks!
My question is, how do you implement DbSet<> when you add the Service and Repository layers?
I originally added these to my ApplicationDbContext file under the Data folder. Is this still correct? Then would I just use DI to call my database on each repository?
C#:
private readonly ApplicationDbContext _context;
public ParkController(ApplicationDbContext context)
{
_context = context;
}
Or do I have my own DbContext for each table? (Where would DbSet<> go then?)
C#:
private readonly ParkDbContext _parkContext;
public ParkController(ParkDbContext parkContext)
{
_parkContext= parkContext;
}
If I am completely off-base here, or talking nonsense, please let me know.
Thanks!