Better to inject IoC container or use a Service Locator pattern? [duplicate]
https://softwareengineering.stackexchange.com/questions/66035
-
31-10-2019 - |
質問
This question already has an answer here:
I have an IoC container (If you want a specific one to look at, it's very similar to Unity) and I'm working on how I want to integrate it into my application. My overall goal for this exercise is to transform this horrendous code I wrote into something much more testable.
I can create the IoC container and register types and I understand the fundamentals of how it is supposed to accomplish it's goal. My question is should I be injecting the container down into objects that need it, or should the objects that need it look it up using a Service Locator pattern? Realistically I see myself having to reference the container in two or three layers of my application.
正しい解決策はありません