I have a View where I am searching my db for an object(i.e. Books)..
My controller for this view depends on a BooksRepository that implements a search method.
Everything works fine. I also have the option to do an advanced search which presents a larger form in a Modal popup. This form has many fields including a Dropdown box to select an ‘Author’ to search by.
I would like to pass a list of authors in my viewmodel so in my conroller I instantiate an instance of my view model, I need to call a repository method to bring back the list of authors‘s…
My thinking is that this GetAuthors() method should be in an AuthorRepository…
Is it bad practice to inject multiple repo’s into a controller? or should I have an Author controller that gets injected with the author repo…and call a method in the Author controller from my BookSearch controller?
I think it’s perfectly fine to refer to multiple repositories in a controller. A controller’s job is to wrap data in a model and pass it to a view, regardless of how it gets to the data. Doing cross-controller calls can get messy.