How to inject model to each other

halley's Avatar

halley

31 Mar, 2011 07:32 AM

ModelA
{ [Inject] public var modelB:ModelB; } ModelB
{ [Inject] public var modelA:ModelA; } this cause a loop...error
ModeA,B are mapSingleton....

  1. Support Staff 1 Posted by creynders on 31 Mar, 2011 11:23 AM

    creynders's Avatar

    You should avoid injecting models into each other.

    There are all kinds of solutions, but they depend on the use case.
    If you need to combine data from 2 models, you can let a command access both models and pass the combined data to the rest of the framework.
    If these 2 models are inherently tight to each other it could be that it's essentially one model. Another option is to have a third model which stores the data from both models. But it's a bit of hassle, because every time one of the two original models updates its data, you have to let a command update the combined data model.

  2. Support Staff 2 Posted by Stray on 02 Apr, 2011 11:36 AM

    Stray's Avatar

    Agreed - this feels like an architectural problem to me. I'd step back and try to solve the problem again in a way that there isn't a co-dependency - just to see what you come up with. You might find it has other advantages too.

  3. 3 Posted by halley on 03 Apr, 2011 02:04 PM

    halley's Avatar

    yes,i have a third model to solve the problem,and really like it.

    thanks~all

  4. halley closed this discussion on 03 Apr, 2011 02:49 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