ssannandeji / Zenject-2019

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

Declaring Signal Type while passing an instance to Fire method #591

Closed b-pos465 closed 5 years ago

b-pos465 commented 5 years ago

Hello Zenject team!

Thank you for your work so far! Your project helps us to take our game code to the next level :)

There is one thing that took us a few hours to solve which doesn't seem to be obvious:

We defined an empty Signal and declared it in our Installer:

public struct EndOfBattleSignal { }
public class ModelInstaller : Installer<ModelInstaller> {

    public override void InstallBindings() {

        SignalBusInstaller.Install(this.Container);
        this.Container.DeclareSignal<EndOfBattleSignal>();
    }
}

After that we tried to fire it:

// This does not work:
this.signalBus.Fire<EndOfBattleSignal>(new EndOfBattleSignal());

// This works:
this.signalBus.Fire(new EndOfBattleSignal());

Surprisingly the first option doesn't work while

this.signalBus.Fire<EndOfBattleSignal>();

does work.

Is there a reason for this behavior? Are we missing something?

We just want to make sure that no one encounters the same problem.

Thank you for your time and keep up the good work!

vrobel commented 5 years ago

Hi, I've stumbled onto this one too. I've just realized that in the first generic case you're passing the object as an identifier parameter not the instance of the signal. I've found it not so intuitive. When you pass an instance please remove the generic declaration type and it'll be fine.

svermeulen commented 5 years ago

Yeah agreed this is confusing. I've now changed the signal bus class to have different method names for the operations that pass in an identifier