Hi guys, I would like to hear from you what are the main advantages and disadvantages of using dependency injection at the controller level and / or domain level.
Let me explain; if I get IUserRepository as a parameter for my user , I can act in two ways:
1) I insert IUserRepository directly on my domain object, then I consume the user at the controller level without creating new objects, this means that I get them ready from the DI container.
2) I insert IUserRepository on my controller (say Register.aspx.cs), and there I add all my domain objects using dependencies that come from the DI container.
Yesterday, when I talked with my friend, he told me that if you get your domain objects from the container, you will lose your life cycle control, since the container manages it for you, he meant that it could be a prone error when Work with large xml configuration files. An opinion that is inconsistent with the fact that you can have tests going through each domain object in the assembly, and then it asks for the container, whether it is a singleton, request scope, session scope or application. He fails if either of them is right. A way to ensure that this kind of problem does not happen.
I was more likely to take the approach to domain (1), as I see big savings on repeating lines of code at the controller level (of course, there will be more lines in the XML file).
Another point that my friend raised is that, suppose for some reason you have to go from container A to B and say that B does not support constructor injection (which is the case for the seam container, Java, which manipulates BC or performs its task only with the installation of setter), but its point of view is that if I have all my code at the controller level, I can smoothly reorganize my code, since I get access to such tools like auto- refactoring and auto-completion , Which is not available when you are working with XML files.
I was stuck on this since I needed to make a decision right away.
What approach should my architecture use? Are there any other ways of thinking ???
Do you guys really think this is an urgent issue, should I worry about it?