1

Our application is an enterprise application deployed in a distributed environment. It's an ASP.NET MVC 2.0 project connected to a WCF project on another server. What we need is to make our business modules reusable and testable.

So what is the best decoupling approach when it comes to WCF? Is it the Castle Windsor WCF facility? Or should I use the Common Service Locator approach? And Why?

TRiG
  • 10,148
  • 7
  • 57
  • 107
HEH
  • 305
  • 6
  • 15
  • 2
    You ask too many questions, which make your question very broad and the answers to your questions will be very opinion based. One thing I can point you at is [this article](http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=95) that describes a type of architecture (message based architecture) that will make your application much more flexible, modular and extendible. If you use this architecture, you don't need your container's WCF facility any more. – Steven Aug 04 '13 at 20:12
  • 1
    Thank u for your recommendation, but when creating a command and a commandHandler it is not working unless updating service reference. Do u suggest any dynamic proxy solution for that? Or i am missing something in the solution? – HEH Aug 07 '13 at 13:32
  • 1
    If your commands are part of the contract, adding a new command means you need to update the service reference. If you need more flexibility, try leaving the commands out of the contract; for instance by letting the WCF service have an `Execute(string commandType, string commandData)` method. You can serialize the command as JSON or xml and send it as text to the WCF service that can deserialize it back. This way WCF knows nothing about your commands and your WCF contract does not change. Very flexible. – Steven Aug 07 '13 at 13:37
  • I know also that this is a very opinion based topic. But my questions related to performance are pure technical questions, and opinion based answers can also very useful if they're attached with clear arguments. – HEH Aug 07 '13 at 13:40
  • 1
    I understand that opinion based answers can be very valuable to you, but the Stackoverflow format is not suited for this type of questions. Try writing a new stackoverflow question for each question that you have, and be sure you are specific, and support your question with facts, code examples, etc. You will have much better chance of getting good quality answers to questions. – Steven Aug 07 '13 at 13:50
  • I've just updated this thread into one question that is related to our comments. I will try to compare the solution provided in your article with CSL and Castle WCF facility and try to understand which one is better and fits my needs, and then update the question with some code examples and facts. Thanks again for your support. – HEH Aug 07 '13 at 14:30
  • @Steven can you provide a sample application for Execute(string commandType, string commandData) flexible approach ? – Houssam Hamdan Aug 12 '13 at 10:24

1 Answers1

1

Here's an example of how to create the Execute(string type, string json) method:

[OperationContract]
public void Execute(string type, string json)
{
    Type commandType = Type.GetType(commandType);

    Type commandHandlerType = typeof(ICommandHandler<>).MakeGenericType(commandType);

    dynamic commandHandler = Bootstrapper.GetInstance(commandHandlerType);

    dynamic command = JsonConvert.DeserializeObject(json, commandType);

    commandHandler.Handle(command);
}

The code sample uses JSON.NET to deserialize the JSON to an object. You can also use the XmlSerializer class if you prefer XML.

Steven
  • 166,672
  • 24
  • 332
  • 435