Flex/mate: mate doesn't cache instance, created with Object Builder
If you once run an ObjectBuilder the object instantiated will be cached and next time开发者_C百科 you use an PropertyInjector or something else, the instantiated object will be used instead of creating a new object. Or at least this should be like this :)
But in the example below it seems that mate tries to instantiate the object again:
The following error occurs:
! TerminalPresentationModel - constructor called # dispatcher = [object GlobalDispatcher] !
<Injectors (started) target="[class TerminalPresentationModel]" includeDerivatives="false" dispatcherType="inherit" scope="[object Scope]">
<PropertyInjector sourceKey="currentDate" targetKey="date" source="[class DateManager]" sourceCache="inherit" softBinding="false"/>
---------------------------------------------------------
- ERROR: Wrong number of arguments supplied when calling the constructor
- TARGET: TerminalPresentationModel
- TAG: PropertyInjector
- METHOD: constructor
- FILE: TerminalMainEventMap
- NO ARGUMENTS SUPPLIED
- STACK TRACE: ###SHORTENED###
---------------------------------------------------------
---------------------------------------------------------
- ERROR: source is undefined in tag PropertyInjector
- TARGET: TerminalPresentationModel
- TAG: PropertyInjector
- FILE: TerminalMainEventMap
---------------------------------------------------------
- INFO: Data binding will not be able to detect assignments to date
</Injectors (end) target=[class TerminalPresentationModel]>
! DateManager - constructor called # dispatcher = [object GlobalDispatcher] !
<Injectors (started) target="[class TerminalContainer]" includeDerivatives="false" dispatcherType="inherit" scope="[object Scope]">
<ObjectBuilder registerTarget="true" constructorArguments="[object GlobalDispatcher]" cache="inherit" generator="[class TerminalPresentationModel]"/>
<PropertyInjector targetKey="pm" source="[object TerminalPresentationModel]" sourceCache="inherit" softBinding="false"/>
- INFO: Data binding will not be able to detect assignments to pm
</Injectors (end) target=[class TerminalContainer]>
Any hints what's wrong with my code?
Update 2010-08-16 As requestes by ktutnik, more details: I use an EventMap:
<?xml version="1.0" encoding="utf-8"?>
<EventMap
>
<fx:Script>
<![CDATA[
// imports and namespaces shortened
[Bindable]
public var endpoint:String = "";
]]>
</fx:Script>
<fx:Declarations>
<Debugger level="{Debugger.ALL}" />
<myService:Services id="services" endpoint="{endpoint}"/>
<maps:TimeEventMap endpoint="{endpoint}"/>
<EventHandlers type="{FlexEvent.PREINITIALIZE}">
<ObjectBuilder
generator="{TerminalPresentationModel}"
constructorArguments="{scope.dispatcher}" />
<ObjectBuilder
generator="{DateManager}"
constructorArguments="{scope.dispatcher}" />
<ObjectBuilder
generator="{TerminalFaultHandler}" />
</EventHandlers>
<EventHandlers type="{DataServiceEvent.GET_CURRENT_TERMINAL_STATUS}">
<RemoteObjectInvoker instance="{services.TerminalService}"
method="getCurrentTerminalStatus"
arguments="{[event.locationId,event.actualPlan]}"
showBusyCursor="false">
<resultHandlers>
<MethodInvoker generator="{TerminalPresentationModel}"
method="setCurrentTerminalStatus"
arguments="{resultObject}" />
<MethodInvoker generator="{TerminalFaultHandler}"
method="removeError" />
</resultHandlers>
</RemoteObjectInvoker>
</EventHandlers>
<Injectors target="{TerminalContainer}"
debug="true">
<ObjectBuilder
generator="{TerminalPresentationModel}"
constructorArguments="{scope.dispatcher}" />
<PropertyInjector
targetKey="pm"
source="{lastReturn}" />
</Injectors>
<Injectors target="{TerminalPresentationModel}"
debug="true">
<PropertyInjector targetKey="date" source="{DateManager}" sourceKey="currentDate" />
</Injectors>
<Injectors target="{TerminalContent}">
<PropertyInjector targetKey="faultHandler"
source="{TerminalFaultHandler}" />
</Injectors>
<EventHandlers type="{UnhandledFaultEvent.FAULT}">
<MethodInvoker generator="{TerminalFaultHandler}" method="handleFault"
arguments="{event.fault}" />
</EventHandlers>
</fx:Declarations>
</EventMap>
Flex: 4.0 mate: 0.8.9
put debug="true"
both in your EventHandlers and Injector tag and have a look which one earlier.. try to make combination of CreationComplete event either than PreIntitialize. if im not mistaken in Application CreationComplete is earlier than Preinitialize (but im not realy sure.. because it is confused me too).
It seems that you can't have two ObjectBuilder in one EventMap. This will cause this issue. As I removed the ObjectBuilder in the Preinitialize-Event everything works fine.
This is a strange behaviour because in other places I wrote it like in this case and no problem occured. So I don't really know WHY it works, but it seems that it fixed my problem.
精彩评论