0

I'm starting with Parsley and cannot manage to make the autowire working. My configuration is based on flex 4.5 and parsley 3.0.0.

My application contains the folowing 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>

The configuration is quite simple :

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

And my Panel contains :

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

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


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

I think I did everything right but the model is not injected in my view. The trace indicates :

[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) 

No sign of view processing.

If I add the «manual configuration» in the panel :

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

The injection works:

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

The workaround is quite heavy as it requires adding in all my views the proprietary tags.

Any idea of what is wrong with my configuration?

GaetanZ
  • 2,819
  • 3
  • 21
  • 20

1 Answers1

0

I would recommend that you use another solution. When you configure (or wire) a view, Parsley needs to reflect the class and iterate through all properties to find the injection points. This is costly and time consuming. It might be fine for only a few wired views, but normally that is not the case since if you're using Flex and Parsley, there's a good chance you'll have a lot of views.

The better approach is to create all models, presenters, services, etc. in the parsley config, excluding all Views. In the views, you'd only have to use the FastInject tag as such:

<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> 

This is a much better approach since reflection isn't needed. The only "issue" is that you cannot use Parsley metadata in your views, which is better for separating business concerns from the view. This also helps you reuse presenters throughout your application and help out with testing of said presenters.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • It may work but my problem was to have clean views without dependencies on parsleys. I always find it annoying to use an IoC and have to much framework configuration in the code. The first sentence of http://www.spicefactory.org/parsley/docs/3.0/manual/view.php#config_automatic indicates it should work. – GaetanZ Mar 12 '12 at 17:22
  • Yes, you should be able to do that. Instead of specifying the string of the class, try binding the class directly: `` How are you adding the view to the screen? – J_A_X Mar 12 '12 at 17:43
  • No new, just a tag in my application mxml. – GaetanZ Mar 13 '12 at 08:10