Injection not working :(

ericwfisher's Avatar

ericwfisher

16 Aug, 2013 04:39 PM

Greetings,

I am new to RobotLegs (i.e have never used RL1) and I am having troubles with injection. I have read the common mistakes section and followed all the advice there but still I cannot inject. I am trying to inject a code behind class into a view to provide a click event handler function to a LinkButton but it seems no matter what I do the injected instance is always null. Can anyone here assist?

My current Additional Compiler Arguments are as follows:
-locale en_US -source-path=locale/{locale} -keep-as3-metadata+=Inject -keep-as3-metadata+=PostConstruct -keep-as3-metadata+=Execute -keep-as3-metadata+=Payload -define=APP::version,0.0.0 -define=APP::build,0

I have verified that the case of my [Inject] tags are correct and not followed by a semicolon.

As a side note, I don't seem to be able to get the PostContruct meta tag to work either. I feel like I must have missed some key bit of information along the way. I would be happy to provide a zip of the code to anyone willing to assist.

  1. Support Staff 1 Posted by Ondina D.F. on 17 Aug, 2013 07:17 AM

    Ondina D.F.'s Avatar

    Hey Eric,

    I would be happy to provide a zip of the code to anyone willing to assist.

    Yes, please attach the code, I'll take a look at it.

    Ondina

  2. Support Staff 2 Posted by Ondina D.F. on 17 Aug, 2013 03:51 PM

    Ondina D.F.'s Avatar
    Ondina,
    
    Please find the project attached. Here is what is happening...
    
    When Launching the application you will see a "Login" LinkButton at the top right of the stage. If you click on this button you get an exception because the injected codebehind class LoginButtonCB) is null.
    
    For your reference, the code in question exists in the following package:
    com.fsllc.plexus.components.auth
    
    You will also notice through inspection that the injected model class is also null. Additionally, I attempted to create PostConstruct methods in a variety of different places but I never hit break points set in those methods. It appears to me that the only injection that actually works is that of the Injector class itself. I am very perplexed. Have I missed some key piece of information to set up the project correctly or something like that?
    
    My environment is:
    Flash Builder 4.7
    Apache Flex 4.10.0
    RobotLegs 2.1.0
    
    I have tried several variations on RobotLegs versions and Flex SDK versions as well.
    
    Thank you very much for taking the time to assist. O look forward to learning what you discover.
    
    Eric
    

    I found the culprits:)

    1 you forgot to add ContextViewListenerConfig to the configurations.

    ContextViewListenerConfig - adds the contextView to the viewManager. Without it there is no contextView and any view added to the contextView won't be processed.

    context = new Context()
        .install(AppBundle)
        .configure(AppConfig)
        .configure(AuthConfig)
        .configure(ContextViewListenerConfig, new ContextView(this));
    

    2 ViewProcessorMapExtension - allows direct view processing (e.g. direct injection) [https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...] So, in your AppConfig you inject it:

    [Inject]
    public var viewProcessorMap:IViewProcessorMap;
    

    and then you use it like this:

    injector.map(AppModel).asSingleton();
    viewProcessorMap.map(AuthViewBase).toInjection();
    

    Your app is now working on my end. Let me know how it goes for you.

    Ondina

    P.S. You can delete the attachment (if you want to) and mark the discussion as public

  3. 3 Posted by ericwfisher on 17 Aug, 2013 09:00 PM

    ericwfisher's Avatar

    Ondina,

    Thank you very much for your assistance! It is kind of hard to to make heads-or-tails out of the RL2 documentation without previous knowledge of RL1. I was looking at a variety of different examples using different versions of RobotLegs trying to figure out what I was missing. Thanks again for pointing me down the correct path.

    Do you know if there is any work planned around RL2 documentation outside of the markdown files? Just curious.

    I didn't realize that I had created a private post. I'll change that.

  4. Support Staff 4 Posted by Ondina D.F. on 19 Aug, 2013 10:48 AM

    Ondina D.F.'s Avatar

    You're welcome, Eric!

    It is kind of hard to to make heads-or-tails out of the RL2 documentation without previous knowledge of RL1.

    True. You'll have to read at least the Best Practices, written for RL1, to understand the basic principles.

    Do you know if there is any work planned around RL2 documentation outside of the markdown files? Just curious.

    I don't know if Shaun or creynders are planning on writing a tutorial.
    I am working on a step by step demo, but there are 2 major problems I'm facing: lack of time and poor English skills. English is not my native language and I find myself struggling with words more than necessary, probably because I think a tutorial requires a high level of clarity in a compact form, while, at the same time, all common scenarios are being handled.
    But, I think I'm overanalysing and overcomplicating things, I'll just upload my scribbles on github and wait for it to explode ;)

    This is kind of a burlesque attempt at a tutorial (first draft and not even finished):

    https://github.com/Ondina/robotlegs-bender-modular-air/wiki/Robotle...

    I'll try to find some time to finish the step by step demo + serious tutorial, at least the part for creating a Context.

  5. Ondina D.F. closed this discussion on 23 Sep, 2013 02:34 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