我从Parsley开始,无法让autowire工作。我的配置基于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 :(得分: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>
这是一种更好的方法,因为不需要反射。唯一的“问题”是您不能在视图中使用Parsley元数据,这样可以更好地将业务问题与视图分离。这也有助于您在整个应用程序中重复使用演示者,并帮助测试所述演示者。