Why injections are not happening if i bind interface to Tovalue() ?

21 views
Skip to first unread message

krishna...@juegostudio.net

unread,
Jun 29, 2018, 1:48:44 AM6/29/18
to StrangeIoC
injectionBinder.Bind<ITasksBucket>().ToValue(new TasksBucket {} ).ToSingleton().CrossContext(); 

this is my  binding. i am trying to inejct one signal inside of tasksbucket class but it is giving null value... that signal is alreay bindded in context before this binding.

krishna...@juegostudio.net

unread,
Jun 29, 2018, 2:09:23 AM6/29/18
to StrangeIoC


On Friday, June 29, 2018 at 11:18:44 AM UTC+5:30, krishna...@juegostudio.net wrote:
injectionBinder.Bind<ITasksBucket>().ToValue(new TasksBucket {} ).ToSingleton().CrossContext(); 

this is my  binding. i am trying to inejct one signal inside of tasksbucket class but it is giving null value... that signal is alreay bindded in context before this binding.

i think is fine, i am trying to adding listener before injection... but listensto attribute is not working for tovalue bindings
 

wcorwin

unread,
Jun 29, 2018, 2:14:10 AM6/29/18
to StrangeIoC
You don't need to do a ToValue here, although may just be doing that for demonstration. You can do the above with either:

injectionBinder.Bind<ITasksBucket>().To<TasksBucket>().ToSingleton().CrossContext()

or an annotation:

[Implements(typeof(ITasksBucket), InjectionBindingScope.CROSS_CONTEXT)]

To be clear on your issue, you're using ListensTo in a mediator, and the signal you're binding is not being injected? Could I see the signal you're binding and listensto calls? Is this TasksBucket class related somehow?

krishna...@juegostudio.net

unread,
Jun 29, 2018, 2:17:47 AM6/29/18
to StrangeIoC
I am using Listento attribute in TasksBucket class...  


injectionBinder.Bind<StartTaskSignal>().ToSingleton().CrossContext();

            injectionBinder.Bind<ITasksBucket>().ToValue(new TasksBucket { }).ToSingleton().CrossContext();
 


these are my bindings and i am trying to add listensto attribute in tasksbucket class...  

wcorwin

unread,
Jun 29, 2018, 2:19:10 AM6/29/18
to StrangeIoC
Oh, is TasksBucket a Mediator? ListensTo only works in SignalMediator, and requires use of the SignalMediationBinder in that context.

wcorwin

unread,
Jun 29, 2018, 2:19:50 AM6/29/18
to StrangeIoC
Sorry I meant ListensTo only works in Mediator, forgot we ditched the SignalMediator class long, long ago.

krishna...@juegostudio.net

unread,
Jun 29, 2018, 2:21:23 AM6/29/18
to StrangeIoC


On Friday, June 29, 2018 at 11:49:50 AM UTC+5:30, wcorwin wrote:
Sorry I meant ListensTo only works in Mediator, forgot we ditched the SignalMediator class long, long ago.


just now i have seen to framework code.. signalmediationbinder...

can't we make listensto attribute for class models.. no my Tasksbucket is just class 

wcorwin

unread,
Jun 29, 2018, 2:27:19 AM6/29/18
to StrangeIoC
There should be far fewer listeners in your models, so my initial answer is no. It seems more likely you're making a little bit of a mistake there. Admittedly, this is all subjective, but I like to think I have a good handle on how to use strange :D

I just did a quick find in my entire unity project and found 186 hits for AddListener inside my view folder (not including ListensTo, which is a ton of mediators) and zero in my models/services. I've found Commands are better off at handling the access and adjustment of data inside your models. So I set them up to listen to signals and do work in those commands. I'd be happy to help you figure out more or hear your suggestions. And I'm always happy to review a PR for a feature.

krishna...@juegostudio.net

unread,
Jun 29, 2018, 2:34:52 AM6/29/18
to StrangeIoC


On Friday, June 29, 2018 at 11:57:19 AM UTC+5:30, wcorwin wrote:
There should be far fewer listeners in your models, so my initial answer is no. It seems more likely you're making a little bit of a mistake there. Admittedly, this is all subjective, but I like to think I have a good handle on how to use strange :D

I just did a quick find in my entire unity project and found 186 hits for AddListener inside my view folder (not including ListensTo, which is a ton of mediators) and zero in my models/services. I've found Commands are better off at handling the access and adjustment of data inside your models. So I set them up to listen to signals and do work in those commands. I'd be happy to help you figure out more or hear your suggestions. And I'm always happy to review a PR for a feature.

so, rather than injecting signals into model, better to have a commands for models right? 

wcorwin

unread,
Jun 29, 2018, 3:03:56 AM6/29/18
to StrangeIoC
Yeah, I'll typically bind these signals in my commands and my mediators. Then when a user does something, I can pop that data to a command, and the command injects, and then updates the model with the new data.

Rarely, I'll inject the Model directly into the Mediator. Particularly in smaller projects and when I get good usage from doing so. Like if I can avoid creating several commands that are very similar. 
Reply all
Reply to author
Forward
0 new messages