The main advantage of using the dependency injection framework is IoC (control inversion):
- weak connection
- great flexibility
- easier testing
So, what is usually done is to enter repositories through their interfaces, for example
public class MyController : Controller { private IPersonRepository personRepo; public MyController(IPersonRepository personRepo) { this.personRepo = personRepo; } ... }
During testing, this makes it easy to enter my false repository, which returns exactly the values ββthat I want to check.
Injection of domain objects does not make such a sense, since they are more closely related to the functionality in a particular class / controller, and thus, their abstraction will be just an overhead rather than a benefit. Instead, if you want to separate your actual entity model from the controller , you can take a look at the MVVM template by creating specialized "ViewModels".
Just think about controlling your controller: "What would I like to mock unit test it?"
- Access to the database β repository
- External dependencies -> other BL classes, WS calls, etc.
I would not include domain objects here, since they usually represent a container .
source share