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.
However in my Services Layer I have something similar to below:
public class MyService : IMyService
{
private readonly ExternalServiceClient _externalServiceClient;
public MyService()
{
_externalServiceClient = new ExternalServiceClient("WSHttpBinding_IExternalService");
}
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.
So my constructor would look like:
private readonly ExternalServiceClient _externalServiceClient;
public MyService(ExternalServiceClient externalServiceClient)
{
_externalServiceClient = externalServiceClient);
}
where - externalServiceClient is either a new
ExternalServiceClient("WSHttpBinding_IExternalService");
or my stubbed version of the external client.
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?