Suppose I instantiate two sub-objects in Mate event map:

<EventMap>
...
    <ObjectBuilder generator="{SubModelA}" />
    <ObjectBuilder generator="{SubModelB}" />
...
</EventMap>

...and one main object which must contain previous objects in a collection:

...
<ObjectBuilder generator="{MainModel}" />
...

How can I assign created SubModelA and SubModelB objects as a collection to property in MainModel by using Mate?

1

There are 1 answers

0
Georgi Hristozov On

You'll have to use the Mate PropertyInjector to inject them in an appropriate setter in MainModel, which handles the collection logic. Something like:

<ns:Injectors target="{MainModel}">
    <ns:PropertyInjector source="{SubModelA}" targetKey="updateCollection"/>
    <ns:PropertyInjector source="{SubModelB}" targetKey="updateCollection"/>
</ns:Injectors> 

Of course, you'll have to add a lot of checks for already added models in the updateCollection method. With custom [Bindable] metadata you'll even support binding to the collection in MainModel. It is a bit ugly (and, actually, a very bad use of dependency injection), but I'm pretty sure you wouldn't be able to instantiate any collection from the EventMap in a reasonable way. The other way is to create your custom Mate action (it's not that hard, see the sources for hints how to do it). You may also consider simplifying your design.