I am creating a middle-size WEB-application based on PHP without Frameworks. My app should have 3-5 objects, which can be used in any class. For example, it is a global client-instance from Guzzle Http Library, which is used to send requests to API. I read about Dependency Injection pattern. But, I think it must be another way to solve my problem, because there would be a lot of classes, which should use this global client-reference. I don't want to pass a reference to setters/constructors of each class or create interface (Or is it a good idea?). I have also tried a Service Locator, which, in my opinion, is better than DI in this case, but a lot of people said, that it is anti-pattern, which should be avoided. So, I don't know what would be better for my application, which I am going to support and update in future. What should I do in this situation? Thank you!
Aucun commentaire:
Enregistrer un commentaire