title: Initializing a database client in a trait
body: <p>I have a trait DbClientUtil that is as follows:</p>
  
  <pre><code>trait DbClientUtil{
     lazy val dbClient = //Initializing client here
  }
  </code></pre>
  
  <p>I have a Dbhelper object that extends the DbClientUtil trait as follows:</p>
  
  <pre><code>object DbHelper extends DbClientUtil{
     def sendDbPayload(dbModel:DbModel):Unit = {
          dbClient.sendData(dbModel)
     }
  }
  </code></pre>
  
  <p>In the above given example <code>sendData</code> is a method on <code>dbClient</code>.</p>
  
  <p>Now I want to iterate through a collection, convert the elements to a model, send it to the db and then shutdown the client.</p>
  
  <p>So, I write out this strategy in the following object</p>
  
  <pre><code>object Runner extends DbClientUtil{
     import DbHelper._
     List(DbModel("model1"),DbModel("model2"),DbModel("model3")).foreach{
        model =&gt; sendDbPayload(model)
     }
     dbClient.shutdown
  }
  </code></pre>
  
  <p>I have two objects that extend the same trait. <code>DBHelper</code> and <code>Runner</code> extend the same trait <code>DbClientUtil</code>. The <code>DbClientUtil</code> initializes the <code>dbClient</code>. The initialized <code>dbClient</code> is being used by both the  <code>DbHelper</code> and the <code>Runner</code>. My question is, am I initializing <code>dbClient</code> twice? My next question would be if I am initializing it twice, what would be a better way to rewrite this to prevent any redundant initializations?</p>
  
  <p>Thanks</p>