Sharing Models Between Modules

john.amedo's Avatar

john.amedo

01 Aug, 2012 04:46 PM

Using the modular utility from Joel Hooks. Which by the way, is the SWC no longer in the github download? I did not see it, needed to build it manually.

Anyway, everything works fine so far. However, I have data that I need to share between modules. I am curious to know if there is a proper way to do this, outside of me hacking the data into the custom events. There are quite a few models that need to be shared between modules. It would be a lot easier if I could somehow inject those models into multiple modules.

Each module is SWF, loaded dynamically at runtime.

Thoughts/suggestions would be appreciated.

Thanks,
John

  1. Support Staff 1 Posted by Ondina D.F. on 02 Aug, 2012 10:07 AM

    Ondina D.F.'s Avatar

    Hey John,

    The keywords are parentInjector, child injectors.

    From Joel’s tutorial (http://joelhooks.com/2010/05/02/modular-robotlegs/#respond):

    When the parentInjector is set, the module context uses it to create a child injector. This child injector has a reference to its parent and the parent’s injection mappings. This means that if you don’t create a mapping in the child injector it will supply the injection a mapped within the parent (or grandparent).

    The parent has no reference at all to the child, and doesn’t even know that it exists so if you create mappings in a child injector they are not reflected up the injector chain to ancestors. If you create a mapping that is identical to a mapping within an injector’s family tree, the first mapping is honored and the injector will not check with its ancestors to see if the mapping exists.

    The IModule interface provides a setter for the parentInjector

    Also look at Stray’s answers in these threads:

    http://knowledge.robotlegs.org/discussions/problems/252-singelton-i...

    http://knowledge.robotlegs.org/discussions/problems/261-modular-uti...

    Here Till’s explanation of Child Injectors:
    https://github.com/tschneidereit/SwiftSuspenders/tree/childinjector...

    I know, I know, it is a lot of reading, but hopefully it will help you…. :)

    Ondina

  2. 2 Posted by john.amedo on 07 Aug, 2012 02:51 PM

    john.amedo's Avatar

    Thanks for the explanation. I understand now.

  3. john.amedo closed this discussion on 07 Aug, 2012 02:51 PM.

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