title: Optionality in Dependency Injection (StructureMap)
body: <p>I know that constructor's injection should be applied when managing dependencies that are really required for the correct working and behaving of the class.</p>
  
  <p>Even so I would like to expose this example. Let's assume a MailServer class:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class MailServer : IMailServer
  {
      public MailServer(ServerData serverData)
      {
          _serverData = serverData;
      }
  
      public void SendMail(MailData mailData)
      {
          //Work with mailData instance and send mail
          ...
          smtp.Send(mail);
      }
  }
  </code></pre>
  
  <p>ServerData contains the information that is needed to know how to send the mail, for instance: Server IP Address, FROM Source address, FROM password. MailData contains the required body and the addresses where you want to send your mail.</p>
  
  <p>Both are required dependencies. <strong>Which bothers me and what I don't know how to solve is that ServerData maybe different in different locations of the application</strong>. If the IMailServer is used in the Invoice System maybe the mail should be from 'invoices@domain.com' but nevertheless, if it's used in in other area, it should be from 'notifications@domain.com'.</p>
  
  <p>I don't know what It's the correct way to manage this. As far as everything related with Dependency Injection, I would like to know good practices related to functionalities as the exposed. This code always ends up in almost every application and it would be great to know how it must be done.</p>
  
  <p>Thanks a lot!</p>