title: Simple Injector: Inject External Web Service
body: <p>I am having some difficulty in how to configure DI correct using SimpleInjector.  I have an external Web Service which bindings are located in Web.config file.  My external Web service lives in Services Layer.  My Web Layer contains the composition root which calls my Domain layer to register services - the domain layer then will call the DAL layer and the serviceslayer to register services it needs.  This will work ok and then in my Domain layer I can use the injected service I have created on servvices Layer in the Domain Service Layer constructor.</p>
  
  <p>However in my Services Layer I have something similar to below:</p>
  
  <pre><code>public class MyService : IMyService
  {
  
      private readonly ExternalServiceClient _externalServiceClient;
  
      public MyService()
      {
          _externalServiceClient = new ExternalServiceClient("WSHttpBinding_IExternalService");
      }
  </code></pre>
  
  <p>This design may not the best because it tightly couples MyService to relying on the external ServiceClient - what I want to achieve is the ability to have my own Stub of this external client and then easily switch between either the actual externalservice client or my stubbed version off the external service client.</p>
  
  <p>So my constructor would look like:</p>
  
  <pre><code>    private readonly ExternalServiceClient _externalServiceClient;
  
      public MyService(ExternalServiceClient externalServiceClient)
      {
          _externalServiceClient = externalServiceClient);
      }
  </code></pre>
  
  <p>where - externalServiceClient is either a new </p>
  
  <p><code>ExternalServiceClient("WSHttpBinding_IExternalService");</code> or my stubbed version of the external client.</p>
  
  <p>What I am not sure off with SimpleInjector is how to get this wired up correctly so I can switch easily between which ExternalClient is passed into the constructor?</p>