ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.53k stars 366 forks source link

Is there a specific reason to fire Signals based on static type ? #652

Open FriedrichWessel opened 4 years ago

FriedrichWessel commented 4 years ago

Hello Zenject team,

I started working with the new Signalbus and stumbled over the following Fire a signal with:

_signalBus.Fire(new SpecialSignal()) works fine.

But if I move the creation to a factory:

SignalFactory { InterfaceForSignal Create(){return new SpecialSignal();} }

The signal is fired with the static type: InterfaceForSignal instead of the dynamic type SpecialSignalwhich of course means that a subscribe does not work in the Special type.

From what I see in the bus code it looks like the typeof() instead of GetType() here is the reason (SignalBus line: 77):

public void FireId<TSignal>(object identifier, TSignal signal)
        {
            // Do this before creating the signal so that it throws if the signal was not declared
            var declaration = GetDeclaration(typeof(signal.GetType), identifier, true);

            declaration.Fire(signal);
        }

So question is: Is there a specific reason to fire based on the static type - or can I change that to GetType and open a PR ?

Best regards and thanks for your help Friedrich