Re: Brand new RL2 (test) project, injection issue [Robotlegs 2]
Injections aren't available in a class constructor. Instead, make it a
public method (the name doesn't matter but I like to use "initialize()" or
"configure()" -- but that's pure opinion.
Then add the [PostConstruct] metadata over the method. A method marked
PostConstruct is called immediately after injections are fulfilled, so
that's a general-purpose mechanism for specifying a class entry point for a
class where you're using injections.
RL2FirstAppConfig.as
package net.tw.test.rl2firstapp {
import net.tw.test.rl2firstapp.views.
>
> MainView;
> import net.tw.test.rl2firstapp.views.MainViewMediator;
>
> import org.swiftsuspenders.Injector;
>
> import
> robotlegs.bender.extensions.mediatorMap.api.IMediatorMap;
>
> public class RL2FirstAppConfig {
>
> [Inject]
> public var mediatorMap:IMediatorMap;
>
> [Inject]
> public var injector:Injector;
[PostConstruct]
public function configure() {
> trace('RL2FirstAppConfig', mediatorMap,
> injector);
>
> //mediatorMap.mapView(MainView).toMediator(MainViewMediator);
> }
> }
> }
>
FWIW, I personally prefer not to have to know to use [PostConstruct] in
this case (although it's a useful technique for general purposes). I have
filed an issue where I've proposed an alternative, and I think Shaun's
doing some thinking about how he thinks it should be done best:
https://github.com/robotlegs/robotlegs-framework/issues/72
Paul
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
Support Staff 1 Posted by Ondina D.F. on 27 Apr, 2012 12:35 PM
+1
Support Staff 2 Posted by Shaun Smith on 27 Apr, 2012 12:53 PM
I'm thinking of adding a Config class in the mvcs package which users can extend, overriding a "configure" method, for convenience.
3 Posted by Paul Robertson on 27 Apr, 2012 06:43 PM
Just curious, what do you think of having an IConfig interface in the core
that defines the configure() method, and have that be what RL core actually
uses when Context.config() is called?
That would mean that if I don't want to inherit Config I can still make my
own config class that works by implementing IConfig. If I create my own
bundle, I don't necessarily want to have to duplicate the MVCS bundle's
Config class in my bundle. =)
Paul
Ondina D.F. closed this discussion on 27 Aug, 2012 10:37 AM.