Spicefactory Forum Index Spicefactory
Forum Archive
 
 SearchSearch    Log inLog in 

Context/Scope problem

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



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

PostPosted: Sat Jun 02, 2012 10:50 am    Post subject: Context/Scope problem Reply with quote

I have a "situation" in my code, where I have one main Context and one or two child Context created during runtime. To visualize it better, it's a comparison mode in graphical program turned on (2 child contexts) or off (just one child context).

Let's say I have two instances of my data in main context - picture1 and picture2, both of the same type. I would like to have this data as part of model in my main context (this is easy, obviously), and also I would like to have picture1 in first child context and picture2 in second one.

Ideally, I would like to have a PublishSubscriber system here, so that picture1 data is shared by main context and first child context and picture2 is shared by main context and second child context. picture1 would be PublishSubscribe in one custom scope, picture2 would be PublishSubscribe in another custom scope.

How do I do that? I've tried different combinations of global/local scopes, custom scopes, but to no avail. At first I thought I can draw the "route downwards" of my custom contexts (by creating scopes only in these parts of tree I want, so it would be a "tree path", not whole tree), but it seems (from documentation) that I can only have it in complete tree-like structure at certain level. I was trying (as an experiment, because it doesn't make much sense) to create two inheritable custom scopes in main view, and then in child views, when creating subcontexts, set (via MessagingSettings) default receiver scope, but this is also not working (child context never received the value).

Is there any smart way to achieve that? Or, if I'm getting it wrong, is there a better way of accomplishing this? The other solutions for passing object would be:
- passing it just in view constructor, then, when context is created, add it internally from view (ie. passing event from presentation model or inject as runtimeinstance during context creation)
- wait for the child context to be initialized and then pass an event with an instance and make child context obtain the data.

My problem with 1st is that I'm leaving a trail of object passing in my view. This breaks encapsulation and OO for me. View should only know about it's PM's data, not the big picture. There's a property (or method) in view just for passing some data upwards - seems a forced solution, when there's IoC container to helpw ith that.
The 2nd solution is problematic, because it has timing issues. I need to wait for context to be completed (at the view level, using complete event), and then somehow pass this information back from my view to this part of application that manages my control, then from there pass an event with the data. Still, if I had 2 child contexts, they would both react to that event, making it even more complex.

With databinding/decoupled binding, it's all very smooth. You just set data and make some rules. Whenever the child complex is created and ready, it will get the data in place. I would like to use this mechanism.

Additionally, in my projects, I often find out that I'm using the same definition for Child Context, yet I need to customize it during runtime, assigning some kind of id or passing additional data to custom object (in form of bindable property that could be later used in context mxml) + but purely as configuration data, not managed objects that should persist there. This is also somehow needed here, because I have two instances of same type, cannot use injection by type, have to use direct ids. But if I have two different ids, how will child contexts know which one to use/pick, if they use the same Context definition?

I saw a request for something similar - http://www.spicefactory.org/forum/viewtopic.php?t=422 - but I don't think this is implemented yet?
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