Let's say I have a Spring Boot class:
public class SomeClass {
private ApplicationContext applicationContext;
private MessagingService messagingService;
private ClientReportFactoryImpl clientReportFactory;
private TerminalReportFactoryImpl terminalReportFactory;
private XMLView xmlView;
private PrepareXMLService prepareXMLService;
And I have a constructor in that class:
@Autowired
public SomeClass (ApplicationContext applicationContext, MessagingService messagingService, ClientReportFactoryImpl clientReportFactory,
TerminalReportFactoryImpl terminalReportFactory,
XMLView xmlView,
PrepareXMLService prepareXMLService) {
Assert.notNull(applicationContext, "ApplicationContext must not be null!");
this.applicationContext = applicationContext;
Assert.notNull(messagingService, "MessagingService must no be null!");
this.messagingService = messagingService;
Assert.notNull(clientReportFactory, "ClientReportFactory must not be null!");
this.clientReportFactory = clientReportFactory;
Assert.notNull(terminalReportFactory, "TerminalReportFactory must not be null!");
this.terminalReportFactory = terminalReportFactory;
Assert.notNull(xmlView, "XMLView must not be null!");
this.xmlView = xmlView;
Assert.notNull("PrepareXMLService must not be null");
this.prepareXMLService = prepareXMLService;
}
Is it considered bad practice to use that many dependencies in a class constructor? Should I refactor my classes so that there are only 1-2 DI's in a constructor?