Orchard CMS multiple dependency classes for the same interface
When using multiple implementations of the same service, what's the best way to specify which dependency Orchard CMS should inject?
For example, I need to use a Fake / Mock implementation for a web service user class in my development environment, but in a test / UAT / production environment, I need to use a real implementation. for example Interface:
public interface IWebServiceClient : IDependency {...}
Real implementation:
public class WebServiceClient : IWebServiceClient {...}
Fake implementation:
public class FakeWebServiceClient : IWebServiceClient {...}
Using Autofac on a non-Orchard site, I can use the ConfigurationSettingsReader and list my fake dependencies as overrides in the web.config. These overrides will be removed by transforming the web.config for non-debug deployments.
source to share
The easiest way to do this is to do every function.
[OrchardFeature("MyModule.Live")]
public class WebServiceClient : IWebServiceClient {...}
[OrchardFeature("MyModule.Test")]
public class FakeWebServiceClient : IWebServiceClient {...}
Then just define those functions in your Module.txt and enable the test on your computer and live in uat / live
source to share