1

I am creating an mvc project, for simplification i have two entitys: Movies and MoviesGenre.

I want to display a list of genres and the amount of movies each of them contains.

Now i have a problem with the design. I am not sure who is responsible for it. I solved that by creating a method in MovieController that returns the amount of movies by genre id and created a method on the MoviesGenreController that select all the genres and uses the MovieController(By instantiating an object) method to get their count.

That doesn't seems like good design to me. Which controller is responsible for this? Do I maybe need to create an extra controller for this logic? Thanks.

2
  • Show some code to better explain the problem. Commented Jul 28, 2019 at 15:04
  • That said, create specific services that can be injected into your controllers to provide the desired functionality. Commented Jul 28, 2019 at 15:05

1 Answer 1

1

You need a data layer project which will manage the access of each controller to the underlying database. I would suggest the following design:

  • create a library project (DataLayer) project which connects to the database. Potential methods exposed:
  • List GetAllGenres();
  • List GetMoviesByGenre()

You can either inject the DataLayer as a service or just simply allocate a new object in each controller ctor. This is more like a personal preference... The DI approach is more flexible a more in line with the DotNetCore architecture.

Both MovieController and MovieGenreController should use the methods from the DataLayer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.