I have an application which uses an interface IBackend for communicating with a backend. In the production environment I wish to use class ProdBackend : IBackend as the implementation of the interface. In the test environment I wish to use TestBackend : IBackend.
The application is packaged into a zip file, which must be independent of whether it is deployed in the prod or test environment.
How can I make the application use a different implementation of IBackend depending on the environment it is deployed in?
Can I do this by simply having to different .dll’s installed in the two environments and naming the classes the same?
UPDATE 11:12 – 15/1:
The packaged application is not allowed to include the prod implementation, i.e. ProdBackend : IBackend. So the application does not know ProdBackend : IBackend at compile time.
Supplying different DLL’s with different implementations of the same interfaces would work fine.
An more elegant solution would be to do this but to add a Service Locator that supplies the implementation you need. Then you could configure the Service Locator to return an implementation based on the platform you run on.
There are many service locators out there, but a simple one that runs on all platforms supported by Mono is TinyIOC