Announcement Announcement Module
Collapse
No announcement yet.
[Autowired] property in constructor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Autowired] property in constructor

    Hi again
    I'm going forward in the study of SAS, and I'm trying to use the metadata [Autowired] to inject the properties into a class.
    In the test I did, I saw that the property to be injected is null when I'm in the class constructor.

    my question is: can I get properties with [Autowired] and use them immediately in the constructor? or [Autowired] happens next?

    Code:
    [Command(eventType="startupEvent")]
    	public class StartupCommand extends GenericOperationCommand {
    		[Autowired]
    		public var appModel : ApplicationModel;
    
    		public function StartupCommand() {
    			super(LoadURLOperation, appModel.url);
    		}
    My intention is to retrieve the url to load from appModel, but in constructor this property is not available.
    I know that i can use a <constructor-arg > tag in application-context.xml, but [Autowired] solution seems to be so elegant

    When the execute method is performed, however, the property is accessible.
    For now the solution I adopted is this

    Code:
    public function StartupCommand(appModel:ApplicationModel) {
    			super(LoadURLOperation, appModel.url);
    		}

    Thanks, and sorry if I'm full of questions, but this framework inspires me a lot and I would like to start using it professionally, but without these tests i cannot tell my boss "I'm sorry but I'm not inside at the time of delivery because I have developed with a framework that I do not know "

    Marco

  • #2
    chicken and egg problem

    Hey Marco,

    you need to understand how SpringAS injects properties into an object instance, its very easy because its exactly the way you would create an object and assign properties in actionscript.

    What SAS does is basically this:

    var object:StartupCommand = new StartupCommand();
    object.appModel = new ApplicationModel();

    Do you see now that its completely logical that the appModel property isn't set yet when you try to access it in the constructor?

    Hope that clears things up a little for you And don't apologize for asking questions, we're happy to help

    cheers,

    Roland

    Comment

    Working...
    X