shahzad
shahzad

Reputation: 3

Any tips or suggestions to this idea/architecture?

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?

Upvotes: 0

Views: 86

Answers (2)

Sebastian Weber
Sebastian Weber

Reputation: 6806

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.

Upvotes: 1

henginy
henginy

Reputation: 2071

I think you should avoid an extra WCF layer if system performance is a critical issue and there aren't any other requirements driving the design this way. You might perform some performance tests to see if its overhead would be acceptable to you though. In the end you can decide which option is better for you and so, remove the need to switch.

Upvotes: 1

Related Questions