title: how to create and manage wcf service clients?
body: <p>At first I treated them as any dependency passing them in the ctor to the class consuming the service:</p>
  
  <pre><code>var serviceConsumer = new ServiceConsumer(new MailingServiceClient())
  </code></pre>
  
  <p>The problem was that once an exception was thrown from the service it entered a faulted state and would not reply to any requests, so re-initialization was due.</p>
  
  <p>Further more, I became familiar with the fact that wcf services may not be disposed properly on several occasions, because the dispose method of the generated proxy is broken (calls close without checking the fault state) and encountered a couple of ways to overcome that:</p>
  
  <ol>
  <li><a href="http://old.iserviceoriented.com/blog/post/Indisposable+-+WCF+Gotcha+1.aspx" rel="nofollow noreferrer">wrapping every call to every service.</a></li>
  <li><a href="http://blog.davidbarrett.net/archive/2007/11.aspx" rel="nofollow noreferrer">override the default IDisposable behavior of the scvutil.exe-generated class</a> </li>
  </ol>
  
  <p>Since I wouldn't like the consumer code to create the service client himself for testing reasons, my questions are:</p>
  
  <ul>
  <li><p>how can I maintain a working un-faulted service?</p></li>
  <li><p>how can I still use dependency injection for testability?</p></li>
  </ul>