Is there any layer where it is bad practice to use DI? In a previous question a user mentioned that DI should only be used in the UI layer.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think that you might be misinterpreting the answer provided by Daren Dimitrov. Unless I’m mistaken, the line that spawned this question is: “Also you shouldn’t be creating a dependency with the DI framework in the business layers of the application.“
I believe what he is saying is that all dependency information/mappings should be be created at the highest level of an application. That is not to say that dependencies will not be present throughout all tiers of your application, just that the lower levels are not responsible for setting up the mappings.
If my interpretation is correct then I agree with him – set up your dependency mappings at the surface of your application. If instead he is saying that you should never resolve a dependency in the lower layers then I would have to disagree.