Spicefactory Forum Index Spicefactory
Forum Archive
 
 SearchSearch    Log inLog in 

How to inject message properties into a command?

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory
View previous topic :: View next topic  
Author Message
Ocelot20



Joined: 02 Oct 2013
Posts: 4

PostPosted: Wed Oct 02, 2013 7:17 pm    Post subject: How to inject message properties into a command? Reply with quote

First off, sorry if this is a newbie question, I'm just getting started with the framework (looks great so far!).

I have some existing commands that I'd like to now be managed in Parsley. Take the following command example:

Code:

public class GetRecordCommand
{
    public var recordId:int;

    public var service:RecordService;

    public function execute():void {
        service.GetRecord(this.recordId);
    }
}


I've created a `GetRecordMessage` class that has a `recordId` property that I would rather not reference in this command. I was hoping to be able to do something like this in my config:

Code:

<MapCommand type="{GetRecordCommand}" messageType="{GetRecordMessage}">
    <Property name="recordId" value="{GetRecordMessage.recordId}" />
</MapCommand


Is there any way to map the properties of the message to the command like this, or will I have to accept the `GetRecordMessage` as an argument to my execute method? Thanks in advance!
Back to top
View user's profile Send private message
Ocelot20



Joined: 02 Oct 2013
Posts: 4

PostPosted: Wed Oct 02, 2013 8:29 pm    Post subject: Reply with quote

This seemed promising, but doesn't work as I expected it to. Perhaps I'm missing something:

Code:

        <MapCommand messageType="{GetRecordMessage}">
            <Command type="{GetRecordCommand}">
                <MessageBinding messageProperty="recordId"
                                targetProperty="recordId"
                                type="{GetRecordMessage}"/>
            </Command>
        </MapCommand>
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Thu Oct 03, 2013 3:00 am    Post subject: Reply with quote

As far as I remember there is no way to do what you want to do. If you need something inside a command you need to inject the full message into it. MessageBinding is not suitable for commands.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
rattkin



Joined: 10 May 2011
Posts: 154
Location: Poznan, PL

PostPosted: Mon Oct 07, 2013 9:24 am    Post subject: Reply with quote

Messages, by design, are usually just a simple objects carrying public variables. Commands, on the other hand, are short-lived objects and it doesn't make much sense for them to be subjects for decoupled binding. If the value would change during execution (async), then it might create another set of problems.

Is there any reason why you don't want to access the message property?
_________________
Sebastian Zarzycki
Feerie Software
Back to top
View user's profile Send private message
Ocelot20



Joined: 02 Oct 2013
Posts: 4

PostPosted: Mon Oct 07, 2013 10:43 pm    Post subject: Reply with quote

rattkin wrote:
Messages, by design, are usually just a simple objects carrying public variables. Commands, on the other hand, are short-lived objects and it doesn't make much sense for them to be subjects for decoupled binding. If the value would change during execution (async), then it might create another set of problems.

Is there any reason why you don't want to access the message property?


I wasn't necessarily trying to make use of decoupled binding, rather I was trying to avoid refactoring my existing Commands to use a Message object. I rely on an existing ICommand interface for this existing project, and it only has an execute() method with no arguments. I didn't see a way to pass messages into the Command constructor either, so I was hoping for some kind of mapping between a Message (newly added to my project) and my Command (pre-existing).
Back to top
View user's profile Send private message
rattkin



Joined: 10 May 2011
Posts: 154
Location: Poznan, PL

PostPosted: Mon Oct 07, 2013 11:28 pm    Post subject: Reply with quote

Understood. Out of curiosity, though, how did you pass recordId to command in your previous solution, then?
_________________
Sebastian Zarzycki
Feerie Software
Back to top
View user's profile Send private message
Ocelot20



Joined: 02 Oct 2013
Posts: 4

PostPosted: Tue Oct 08, 2013 2:00 pm    Post subject: Reply with quote

They were constructor injected. I thought the Message might be available to inject into the constructor with Parsley, but I wasn't able to get that working with a quick test either.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group