Modular utility and Signals; injections don't work within the module context's commands

Mikko Karvonen's Avatar

Mikko Karvonen

05 Jan, 2012 05:34 PM

I'm trying to build a modular application that uses CommandSignal. I've tried combining the Modular utility and SignalCommand as a ModularSignalCommand, but then I found this: https://github.com/bbeaumont/signals-extensions-ModuleSignalCommandMap , which seems appropriate for my use.

Basically, the communication between modules works now (I can dispatch a signal from Module1 that runs a Command in Module2).

In the shell context I'm dispatching an ApplicationStartedSignal. In other modules, I have something like this:

moduleSignalCommandMap.mapSignalClass(ApplicationStartedSignal, DoSomethingCommand);

When the shell dispatches the signal, the commands in my modules are executed as expected. However, only classes that are mapped in the shell can be injected into those commands! Let's say I have a module for all things communication-related. I have a CommunicationContext and within that I have an AMFService, which I inject into the Command classes. If such a Command class is executed by a signal from another context (in this case, the top-level shell), the application just crashes. With a nasty error like this:

Error: Injector is missing a rule to handle injection into property "service" of object "[object DoSomethingCommand]". Target dependency: "modules.communication.service::AMFService", named ""

However, dispatching signals in the scope of CommunicationContext works OK.

If I map the AMFService class in the shell, like this:

injector.mapSingleton(AMFService);

, everything works, but I don't really want to do this as it's not very modular anymore if all module-specific stuff has to be mapped in the shell. And I guess the modules wouldn't work independently anymore.

I started digging into Robotlegs just a couple of weeks ago, so in that sense I'm a newbie. I think what's happening here is that because my ApplicationStartedSignal lives in the shell context, it also tries to execute the communication::DoSomethingCommand in the shell context, and as the injector in the shell knows nothing about its child injectors, it can't map the injection properly. How can I fix this? I'm really starting to like Signals and wouldn't have to revert back to Events at this point.

  1. Support Staff 1 Posted by Shaun Smith on 07 Jan, 2012 04:34 PM

    Shaun Smith's Avatar

    Hi Mikko, is there any chance you could build a stripped down example app that exhibits this behaviour? That would make it much easier to diagnose.

  2. 2 Posted by Mikko Karvonen on 07 Jan, 2012 09:24 PM

    Mikko Karvonen's Avatar

    OK, here you go!

    Clicking "Load MyModule1" crashes right away, because MyModule1Context is listening for an ApplicationStartedSignal and executes MyModuleCommand, which tries to inject SomeVO (which is mapped in MyModule1Context, but still won't work).

  3. Support Staff 3 Posted by Shaun Smith on 08 Jan, 2012 12:59 AM

    Shaun Smith's Avatar

    Ah, indeed, it looks like the wiring in that utility sets things up in such a way that the commands are injected by some shared injector (or something) and not the module's injector. You should create an issue over on that util's repo:

    https://github.com/bbeaumont/signals-extensions-ModuleSignalCommand...

    btw, nice packaging up of the sample app - was really easy to work with.

  4. Ondina D.F. closed this discussion on 10 Feb, 2012 11:51 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac