We have a multi services application. We have moved a method that involves a DB access to a separate component that is exposed by a WCF endpoint.
We have 2 options:
1. A WCF call to the method.
2. Call directly to the method, resolved by our DI engine.
The system performance is a critical issue, so we want to switch between option 1 and option 2 via configuration file with out recompiling client application.
Any tips or suggestions to this idea/architecture?
We have a multi services application. We have moved a method that involves a
Share
You can teach Unity to resolve WCF services by interface. So it does not matter wether you resolve a local implementation of your service or a WCF one. You will always inject an IMyService into your classes. It’s just a change of your configuration.
You can configure the extension to use app.config or WCF discovery or explicitely specify Binding and EndpointAddress in code.
See the TecX project for further information. The source code is located in TecX.ServiceModel.AutoMagic. Some tests that demonstrate the usage can be found in TecX.ServiceModel.Test
Update
Define an interface for your service (e.g. IMyService) and decorate it with the necessary attributes (DataContract, OperationContract). Implement that interface (e.g. in class MyService). MyService calls your method. Now tell Unity to either map IMyService directly to MyService or add the container extension that allows you to map IMyService to a proxy generated by the WCF ChannelFactory. Deploy your service and you are done. Unity will inject whatever implementation of IMyService into the constructors of those classes that need them.