strangeioc/strangeioc — pull request #95 by WillzZz (2014-04-04 08:32:57+00:00)
Title: Polymorphic signal command injections and small event command binder fix

This is two command-related improvements.

The first is a (sorely needed) test and exception handling for EventCommandBinder. Pretty straightforward, and should shine a light on issues which previously were being eaten but causing other direct binding issues.

The second is a first-pass on Polymorphic signal command bindings.

Step One: Dispatch a signal with a payload value of Type T which implements U
Step Two: Create a command which has a property of interface U
Step Three: Properly inject value of Type T in to property of interface U

This goes for multiple interfaces, of course. So if you implement U,V,W,X,Y,Z one of those will be assignable from T, and will be bound.

If more than one interface is found, we will throw a SignalExceptionType.AMBIGUOUS_VALUE_BINDING
This is to avoid weird ambiguity issues which might crop up. For instance, if we Dispatch a signal with a payload of types:

public MySignal : Signal
public OtherSignal : Signal

public class One : U,V
public class Two : V,W

in to a command with injections

[Inject]
public U MyFirstInjection { get; set; }

[Inject]
public V MySecondInjection { get; set; }

Our ordering could result in a success or failure. If we dispatch the types in order , U would be assigned to One, and V would be assigned to Two. However, if we dispatched in order , we would assign U to Two and have nothing to assign One to, and result in a binding failure. It's not an impossible problem to fix, but there are a number of ambiguous states which could arise, and this handles those abruptly.

Most importantly, I am concerned by the performance implications, and hope to utilize the ReflectionBinder for a new version of this. Using reflection at runtime like this with a high load of commands would be a rather dreadful decision.

In any case, I've written a test to prove it, and invite anyone to comment and reply how to make it better. This is just a couple hours work, so hopefully we can improve it and get it live.