Reason for static -> proxy technique in OrdersCommandProxy

Mar 16, 2009 at 5:17 PM
I just stumbled across the code in the commanding example, which looks like this:

    public static class OrdersCommands
        public static CompositeCommand SaveAllOrdersCommand = new CompositeCommand();

    public class OrdersCommandProxy
        public virtual CompositeCommand SaveAllOrdersCommand
            get { return OrdersCommands.SaveAllOrdersCommand; }

I think there was a reason for using a proxy and not refering the static class directly in the code behind file of the example. Does anybody know which reason it was?
[EDIT] When writing this post, it came back to me: You can't databind to static classes... I think thats it?
Thanks, Chris

PS: Here the code behind (is there any way to highligh code here?)

       public OrdersToolBar()
            this.DataContext = new OrdersCommandProxy();
Mar 17, 2009 at 10:24 PM

Hi Chris,


The Composite Application Guidance documentation gives one extra reason to use that technique in the Commanding Quickstart:


"To create a globally available command, you typically create a static instance of a CompositeCommand class and expose it publicly through a static class. This approach is straightforward, because you can access the command instance directly from your code. However, this approach makes your classes that use the command hard to test in isolation, because your classes are tightly coupled to the command. When testability is a concern in an application, a proxy class can be used to access global commands. A proxy class can be easily replaced with mock implementations when writing unit tests."


Hope this helps!


Matias Bonaventura