title: Scala (Play 2.4.x) How to call a class with @inject() annotation
body: <p>I'm looking at the scaly code example from play-mailer: <a href="https://github.com/playframework/play-mailer" rel="nofollow noreferrer">https://github.com/playframework/play-mailer</a> </p>
  
  <p>It goes basically like this:  </p>
  
  <pre><code>class MyComponent @Inject() (mailerClient: MailerClient) {
     ...
  }
  </code></pre>
  
  <p>simple enough and it compiles without compliant </p>
  
  <p>Then I try to "call" it however and there doesn't appear to be a way to satisfy the compiler OR get a working instance of mailerClient. </p>
  
  <pre><code>object AnObject {
    val mailer = new MyComponent
    def sendEmail = mailer.doStuff
  }
  
  [info] Compiling 1 Scala source to ...
  [error] /SomeOne/SomePath/SomeFile.scala:30: not enough arguments for constructor MyComponent: (mailerClient: play.api.libs.mailer.MailerClient) MyComponent.
  [error] Unspecified value parameter mailerClient.
  [error]   val mailer = new MyComponent
  [error]                ^
  [error] one error found
  [error] (compile:compileIncremental) Compilation failed
  </code></pre>
  
  <p>I though I might have gotten close thanks to this: </p>
  
  <p><a href="https://stackoverflow.com/questions/30952505/how-does-inject-in-scala-work">How does @Inject in Scala work</a> </p>
  
  <p>Which indicated that the following syntax might work by removing the <code>@Inject</code> from the constructor and placing it on a field. </p>
  
  <pre><code>@Inject var mailerClient: MailerClient = null
  </code></pre>
  
  <p>However the moment we try to run anything that needs that reference we still get null. </p>
  
  <p>I'm reading everything I can find on @Inject </p>
  
  <p><em>( [warning] [rant] I'm NOT a fan of compiler magic like this for this exact reason -- voodoo magic is wonderful until it stops working then no one seems to have any idea of how to fix it. [/rant] [/warning] )</em> </p>
  
  <p>but what I really want to know is how to use it properly, safely and effectively. </p>