ssannandeji / Zenject-2019

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

Add overload to `SignalBus.Fire` and `SignalBus.TryFire` #595

Closed monry closed 5 years ago

monry commented 5 years ago

Make it possible to pass instances of TSignal to methods using generics.

I need an overload that I can also pass signal to the generic method version of Fire, TryFire to send the spawned instance as signal.

In addition, in the case of the method of the non-generic version, I can not explicitly specify the interface, so I could not do what I really wanted to do.

cooloon commented 5 years ago

(I'm not the author of Zenject, but a man who added TryFire)

So you wanna do like this?

var childSignal = new ChildSignal(); // inherits from ParentSignal
signalBus.Fire<ParentSignal>(childSignal); // Notify on all ParentSignal receivers with ChildSignal instance

If so, that's I've wonder too! 👍

monry commented 5 years ago

Thank you for your replying !

I want to do like below code.

interface IFoo {}
class Foo : IFoo { }

// I am using UniRx linkage, but I want to make `Subscribe <IFoo>' even if I do not use it.
signalBus.GetStream<IFoo>().Subscribe(foo => { /* Do something to use `foo' */ });

var foo = new Foo();
signalBus.Fire<IFoo>(foo);

I want to observe stream used interface.

svermeulen commented 5 years ago

Ok I've added this but made a minor change to your solution where it looks up the declaration before instantiating the signal. This is just a bit nicer for error handling