2012-03-12 87 views
0

我以歐芹開始,無法使自動裝配工作。我的配置基於flex 4.5和parsley 3.0.0。歐芹自動裝配不起作用

我的應用程序中包含如下因素bootrap:

<fx:Declarations> 
    <parsley:ViewSettings autowireComponents="true"/> 
    <parsley:ContextBuilder config="{SimulateurConfig}" /> 

    <s:TraceTarget 
      includeCategory="true" 
      includeLevel="true" 
      includeTime="true" 
      level="{LogEventLevel.DEBUG}" 
      > 
     <s:filters> 
      <fx:String>org.spicefactory.parsley.*</fx:String> 
     </s:filters> 
    </s:TraceTarget> 
</fx:Declarations> 

的配置也非常簡單:

<fx:Declarations> 
    <View type="com.coach.ui.PanelAFinancer"/> 
    <Object type="com.coach.domain.AFinancer" /> 
</fx:Declarations> 

我的面板包含:

<fx:Script><![CDATA[ 
    import com.coach.domain.AFinancer; 

    [Bindable] [Inject] 
    public var model:AFinancer; 
    ]]></fx:Script> 


<s:Label text="Model injected? { model != null }"/> 

我認爲我做的一切都是正確的,但在我看來,這個模型並沒有被注入。跟蹤指示:

[trace] 12:49:12.186 [INFO] org.spicefactory.parsley.core.state.manager.impl.DefaultGlobalDomainManager Using new ApplicationDomain for key [object _Flex_simulateur_mx_managers_SystemManager] 
[trace] 12:49:12.218 [INFO] org.spicefactory.parsley.core.view.impl.DefaultViewManager Add view root: Flex_simulateur0/Flex_simulateur 
[trace] 12:49:12.218 [INFO] org.spicefactory.parsley.core.bootstrap.impl.DefaultBootstrapManager Creating Context [Context(FlexConfig{SimulateurConfig})] without parent 
[trace] 12:49:12.296 [INFO] org.spicefactory.parsley.core.lifecycle.impl.DefaultManagedObjectHandler Configure managed object with [ObjectDefinition(type = com.coach.domain::AFinancer, id = _SimulateurConfig_MxmlRootObjectTag1)] and 0 processor(s) 

沒有視圖處理的跡象。

如果我添加了«手動配置»在面板:

<fx:Declarations> 
    <sf:Configure/> 
</fx:Declarations> 

注射工作:

[trace] 12:56:04.983 [INFO] org.spicefactory.parsley.core.state.manager.impl.DefaultGlobalDomainManager Using new ApplicationDomain for key [object _Flex_simulateur_mx_managers_SystemManager] 
[trace] 12:56:05.015 [INFO] org.spicefactory.parsley.core.view.impl.DefaultViewManager Add view root: Flex_simulateur0/Flex_simulateur 
[trace] 12:56:05.030 [INFO] org.spicefactory.parsley.core.bootstrap.impl.DefaultBootstrapManager Creating Context [Context(FlexConfig{SimulateurConfig})] without parent 
[trace] 12:56:05.124 [INFO] org.spicefactory.parsley.core.lifecycle.impl.DefaultManagedObjectHandler Configure managed object with [ObjectDefinition(type = com.coach.domain::AFinancer, id = _SimulateurConfig_MxmlRootObjectTag1)] and 0 processor(s) 
[trace] 12:56:05.140 [DEBUG] org.spicefactory.parsley.core.view.handler.ViewConfigurationHandler Process view 'Flex_simulateur0.ApplicationSkin3._ApplicationSkin_Group1.contentGroup.viewRoot.PanelAFinancer7' with [Context(FlexConfig{SimulateurConfig})] 
[trace] 12:56:05.155 [INFO] org.spicefactory.parsley.core.lifecycle.impl.DefaultManagedObjectHandler Configure managed object with [ObjectDefinition(type = com.coach.ui::PanelAFinancer, id = _SimulateurConfig_MxmlViewTag1)] and 1 processor(s) 
[trace] 12:56:05.155 [DEBUG] org.spicefactory.parsley.core.lifecycle.impl.DefaultManagedObjectHandler Applying [Property(name=[Property model in class com.coach.ui::PanelAFinancer],value={ImplicitTypeReference(type=undefined)})] to managed object with [ObjectDefinition(type = com.coach.ui::PanelAFinancer, id = _SimulateurConfig_MxmlViewTag1)] 
[trace] 12:56:05.171 [DEBUG] org.spicefactory.parsley.core.view.processor.DefaultViewProcessor Add view 'Flex_simulateur0.ApplicationSkin3._ApplicationSkin_Group1.contentGroup.viewRoot.PanelAFinancer7' to [Context(FlexConfig{SimulateurConfig})] 

的解決方法是相當沉重,因爲它需要將我的所有視圖專有標籤。

任何想法,我的配置有什麼問題?

回答

0

我會建議您使用另一種解決方案。當你配置(或連線)一個視圖時,Parsley需要反映這個類並遍歷所有屬性來查找注入點。這是昂貴且耗時的。只有少數有線視圖可能沒問題,但通常情況並非如此,因爲如果您使用的是Flex和Parsley,那麼很可能會有很多觀點。

更好的方法是在parsley配置中創建所有模型,演示者,服務等,不包括所有視圖。在視圖中,您只需要使用FastInject標籤就可以:

<fx:Declarations> 
    <spicefactory:FastInject property="model" type="{AFinancer}" /> 
</fx:Declarations> 
<fx:Script><![CDATA[ 
    import com.coach.domain.AFinancer; 

    [Bindable] 
    public var model:AFinancer; 
]]></fx:Script> 

這是一個更好的方法,因爲不需要反射。唯一的「問題」是你不能在你的視圖中使用歐芹元數據,這對於從視圖中分離業務關注更好。這也有助於您在整個應用程序中重複使用演示者,並幫助測試演示者。

+0

它可能工作,但我的問題是有沒有依賴於parsleys乾淨的看法。我總是覺得使用IoC很煩人,並且在代碼中需要很多框架配置。 http://www.spicefactory.org/parsley/docs/3.0/manual/view.php#config_automatic的第一句表明它應該起作用。 – GaetanZ 2012-03-12 17:22:09

+0

是的,你應該可以做到這一點。不要指定類的字符串,而是直接綁定類:''你如何將視圖添加到屏幕? – 2012-03-12 17:43:10

+0

沒有新的,只是我的應用程序mxml中的標籤。 – GaetanZ 2012-03-13 08:10:02