title: Refactor service with too many dependencies
body: <p>I'm developing a Web Application with <code>Spring Framework</code>(<code>Spring Boot</code>) and <code>JDBC</code> (no <code>JPA</code> or <code>ORM</code>) so I'm using <code>Dependency Injection</code> to use <code>Beans</code> through layers. The structure is composed by three main layers: DB (DAOs), Service and Controller. <code>DAOs</code> are injected in other <code>DAOs</code> or in <code>Service layer</code> and <code>Services</code> in other <code>Services</code> and in <code>Controller Layer</code>.</p>
  
  <p>My <code>Database layer</code> is composed by one <code>DAO</code> for each the tables of the database. Each <code>DAO</code>has the general <code>CRUD</code>and some specific operations according to its needs. In total I have more than 10 tables (nearly 15 maybe).</p>
  
  <p>Example of DAO</p>
  
  <pre><code>public class Dao1 implements Crud&lt;Entity, Integer&gt;{
  
  
       public Entity findById(Integer id){
            //Impl Jdbc
       }
  
  
       public void insert(Entity entity){
            //JDbc impl
       }
  
  
      //Other CRUD operations -&gt; Update, delete,...
  
  }
  </code></pre>
  
  <p>In the <code>Service layer</code> I map <code>Entities</code> (Database objects) to <code>DTos</code>(Data access object).</p>
  
  <h2>Problem</h2>
  
  <p>I have a <code>@Service</code> class with It is needed to inject too much dependencies (10 dependencies) of data access object. </p>
  
  <p>Why? I've got a complex <code>DTO</code> class which is needed to fill getting some data of each <code>entity</code> (using <code>DAOs</code>) and doing some operations also (<code>Update</code>, <code>insert</code>, <code>delete.</code>....</p>
  
  <p>Example of Service</p>
  
  <pre><code>public class ServiceO{
  
     @Autowired
     private Dao1 dao1;
     @Autowired
     private Dao2 dao2;
     //assume there are 10 daos....
  
     public ObjectComplexDTO findObject(int id){
  
       ObjectComplexDTO dto = mapToObjectComplexDTO(dao1.findById(id));
       dto.setOtherObjects(mapToOtherObjectDto(dao2.findByCompleDto(id)));
       // and so on....
  
       return dto;
  
    }
  }
  </code></pre>
  
  <p>When I reviewed my <code>@Service</code> I saw clearly it`s needed to refactor this class but I'm not sure how.</p>
  
  <p>I have considered the following options:</p>
  
  <ul>
  <li>Create a <code>Class</code> which groups by functionality: but extract data remain too much, 7 dependencies...</li>
  <li>Group <code>DAOs</code> (no just one <code>DAO</code> for <code>Entity</code>) and Make more complex <code>SQL</code> and extract more data giving more functionality to the <code>Database Engine</code> in the <code>Entities</code> of this data that only <code>DTOs</code> has and then filled in <code>DAOs</code> layer: the problem is moved to the layer <code>DAO</code>...</li>
  <li>Keep the class knowing that it has too many dependencies.</li>
  </ul>
  
  <p>Do you have any idea's to improve this issue? </p>