ssannandeji / Zenject-2019

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

New Signals binding "withId()" #552

Closed cpetry closed 5 years ago

cpetry commented 5 years ago

With the previous Signals concept it was possible to bind the signal to an interface with an Id. Is there an alternative in the new signals concept?

cpetry commented 5 years ago

To be more precise: I have several zenjectBinding components with different identifiers. Each gameobject has a script that should use the same signal but with different identifiers. Of course when firing the signals each should call different methods in the end.

svermeulen commented 5 years ago

Unfortunately no, but now that you mention it that would make sense. You'd just have to pass an optional identifier to BindSignal, DeclareSignal, Fire, and Subscribe methods.

cpetry commented 5 years ago

That would be so great! I really would like to use the be signal concept. It's great and easier to use.

svermeulen commented 5 years ago

Ok I'll take a look before the next release

cpetry commented 5 years ago

Then I'll wait till then before I upgrade. Thanks again for your hard work!

svermeulen commented 5 years ago

Ok added in 7.3.0 and 6.5.0

cpetry commented 5 years ago

Well I am able now to declare a Signal with an Id:
Container.DeclareSignal<Signal_UIButtonClicked>().WithId("New");

But I can't bind a signal with an Id to a specific method. Or where would I attach the Id information? Container.BindSignal<Signal_UIButtonClicked>().ToMethod<ISaveLoad>(x => x.OnNew).FromResolve();

svermeulen commented 5 years ago

Oops, you're right I forgot to add it to BindSignal.

svermeulen commented 5 years ago

Fixed on LTS branch and merging to master soon

cpetry commented 5 years ago

Hi again,

I now fetched the newest version (7.3.0) via unity asset store.
Now I am able to Resolve the ID correctly:
_signal = container.ResolveId<Signal_UIButtonClicked>(_identifier);

But I now cannot declare and bind the signal with an ID.

svermeulen commented 5 years ago

Why can't you use WithId like you did previously? Also you should not be able to resolve a signal using container.ResolveId<Signal_UIButtonClicked>(_identifier);. With the new system, signals are temporary parameter objects and are not added to the container

cpetry commented 5 years ago

Strange. Okay I'll check if I updated Zenject correctly.

cpetry commented 5 years ago

you are right. After I reinstalled the unityPackage from the release page here, everything was as expected.

cpetry commented 5 years ago

One last thing:
I can't bind a signal to a bound class with Id.
I would like to do it like this:

 Container.BindSignal<SomeSignal>().ToMethod<IMyClass>(x => x.DoSomething).FromResolve("SomeID");

But there is no possibility to get the resolve with ID.

svermeulen commented 5 years ago

Use From instead and put From resolve inside it