0

I would like to know in best practice questions and think of easily testable classes, when I need multiple different instances of the same (fabricated) object within a specific class, which approach is recommended?

Before I used the Service Manager build method, but it is no longer recommended to inject Service Manager directly into a class, right?

  • Maybe you can write a factory? Inject it to controller and create a new instance via it? – Mehmet SÖĞÜNMEZ Feb 16 '18 at 07:54
  • In fact talking to a member of the community xerkus, we understood that it could be a design problem, since the idea was to have a collection class that delivered a vector of several objects of the same type (Entity). The best way was to create a service that created the vector with the Entities, created an instance of Collection passing the vector to it and returning it in a service method. – Rafael Ortega Bueno Feb 16 '18 at 07:58
  • I don't think if it's a design problem. We've InputFilterPluginManager, FormElementManager etc. These are basically service managers and injecting into forms/inputFilters. So There's nothing wrong if you write some kind plugin manager and inject it to controller/service. Actually there's a class naming as "AbstractPluginManager" (i think) for this purpose – Mehmet SÖĞÜNMEZ Feb 16 '18 at 08:31

0 Answers0