DEV Community

Discussion on: How to Display Junction Tables in .NET Core MVC 3.1

Collapse
 
katnel20 profile image
Katie Nelson

What you are missing are the service and repository layers. Don't go directly to the database from your controllers, go through a service layer and have that service work with the database though a repository layer. Then, multiple controllers can share that service.

Collapse
 
mitchelln11 profile image
mitchelln11

So, then would I connect my service layer to my controllers through dependency injection? Just like the SignInManager?

private readonly SignInManager<IdentityUser> _signInManager;

public HikerController(SignInManager<IdentityUser> signInManager)
{
     _signInManager = signInManager;
 }

What actually goes into the repository layers? Methods to call specific database info?

Collapse
 
katnel20 profile image
Katie Nelson

Yes, through DI. The repository layer has the LINQ queries that interact with Entity Framework. The service layer can map the query data with your view models.

Thread Thread
 
mitchelln11 profile image
mitchelln11 • Edited

This is insightful, thank you. I will give it a go, and see what happens!

Is this still technically considered MVC? Seems like it would be MVCSR

Thread Thread
 
mitchelln11 profile image
mitchelln11

Do the default Data and Areas folders already represent the repository and services layers?

My guess would be that the Data would represent the repository layer, and the Area folder would represent the Service layer. Does that seem about right?