Automagic view injection

jakub.gondek's Avatar

jakub.gondek

12 Sep, 2013 10:32 AM

Hello,

should views get injected automatically by default? Because on a typicall setup when i put [Inject] tag into my view nothing happens?

The readme.md states:

The view processor map provides automagic processing of mapped views landing on the stage and manual processing where preferred.

but my views get injected only when i explicitly call:

viewProcessorMap.map(View).toInjection();
  1. Support Staff 1 Posted by Ondina D.F. on 12 Sep, 2013 12:45 PM

    Ondina D.F.'s Avatar

    Hi Jakub,

    Actually, there is no magic;)

    The Injector "needs to know" how and where to provide dependencies.

    For an injection to occur there are 3 things needed:
    1-Injector - WHO (the Magician??)
    2-Injection point - [Inject] metadata - inside a class that needs injection - WHERE
    3-Injector rule - mapping - WHAT + HOW

    -------Injection rules--------

    Who ----------What--------How
    
    injector.map (SomeClass).asSingleton();
    
    viewProcessorMap.map(SomeView).toInjection();
    
    mediatorMap.map(SomeView).toMediator(SomeMediator);
    
    commandMap.map(SomeEvent.SOME_TYPE).toCommand(SomeCommand);
    

    -------Injection point--------

    public class SomeMediator
    {
    -------Where---------------What
        [Inject]
        public var someView: SomeView;
    

    -------Injection point--------

    SomeView
    -------Where---------------What
        [Inject]
        public var someClass: SomeClass;
    

    Some rules are defined directly with the Injector - injector.map (SomeClass).asSingleton();
    Some others by extensions like the MediatorMapExtension, CommandMapExtension, ViewProcessorMapExtension, but they are making use of the Injector as well.

    A rule defined by the MediatorMap allows the Injector to inject a View into its Mediator.
    Likewise, the ViewProcessorMap allows the Injector to inject dependencies into Views, for example by inspection:
    viewProcessorMap.map(SomeView.toInjection();

    Not all views landing on the stage are automatically processed! Only the ones having a rule (mapping) will be passed to the Injector, inspected and then injected with dependencies. An injection point alone ([Inject]) won't suffice.

    MediatorMap -->injection into Mediators
    ViewProcessorMap---> injection into Views

    See this, too: https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Int...
    It's referring to rl1, but the general ideas are still valid.

    I hope this will help.
    Ondina

  2. Support Staff 2 Posted by Ondina D.F. on 12 Sep, 2013 01:00 PM

    Ondina D.F.'s Avatar

    The readme.md states:The view processor map provides automagic processing of mapped views landing on the stage and manual processing where preferred.but my views get injected only when i explicitly call:viewProcessorMap.map(View).toInjection();

    I should have mentioned that when you create a context and install an MVCSBundle, a couple of extensions will be installed, but that doesn't mean that all of them will be automatically functional. The MediatorMap won't "automagically" map your views to their mediators. I guess the word "automagic" in the documentation is misleading!
    So, if you need to map views to mediators, you'll have to instantiate or have an injected IMediatorMap in your config class. Same for the CommandMap and ViewProcessorMap, they have to be explicitly instantiated and the used for mappings.

  3. 3 Posted by jakub.gondek on 12 Sep, 2013 01:19 PM

    jakub.gondek's Avatar

    Hello,

    thanks for the reply, an the second one too.

    I know general rules for injection, but like you said was misleaded by the
    word `automagic`.

    Best regards
    Jakub Gondek

  4. Support Staff 4 Posted by Ondina D.F. on 12 Sep, 2013 01:54 PM

    Ondina D.F.'s Avatar

    I know general rules for injection, but like you said was misleaded by the word automagic.

    Yeah, sorry, I realized that after I wrote the first answer, thus my second post:)

  5. Ondina D.F. closed this discussion on 12 Sep, 2013 01:54 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