【问题标题】:Parsley autowiring not working欧芹自动装配不起作用
【发布时间】:2012-03-12 16:20:33
【问题描述】:

我从 Parsley 开始,无法使自动接线工作。我的配置基于 flex 4.5 和 parsley 3.0.0。

我的应用程序包含以下引导程序:

<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})] 

解决方法非常繁重,因为它需要在我的所有视图中添加专有标签。

知道我的配置有什么问题吗?

【问题讨论】:

    标签: apache-flex parsley


    【解决方案1】:

    我建议您使用其他解决方案。当您配置(或连接)视图时,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> 
    

    这是一种更好的方法,因为不需要反射。唯一的“问题”是您不能在视图中使用 Parsley 元数据,这更好地将业务关注点与视图分离。这也有助于您在整个应用程序中重用演示者,并帮助测试上述演示者。

    【讨论】:

    • 它可能有效,但我的问题是拥有干净的视图而不依赖于欧芹。我总是觉得使用 IoC 很烦人,而且代码中有很多框架配置。 spicefactory.org/parsley/docs/3.0/manual/… 的第一句话表明它应该可以工作。
    • 是的,您应该能够做到这一点。与其指定类的字符串,不如直接绑定类:&lt;View type="{PanelAFinancer}"/&gt;你是如何将视图添加到屏幕上的?
    • 没有新的,只是我的应用程序 mxml 中的一个标签。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 2016-03-10
    • 2013-01-20
    • 2015-02-15
    相关资源
    最近更新 更多