PDA

View Full Version : Inherit dictionary keys


magistral
05-03-2007, 01:39 AM
Hi, i have this object definition:

<object type="SelectClassSerie.aspx" parent="instrumentPage">
<property name="Results">
<dictionary>
<entry key="OkCommand" value="redirect:~/Web/UseCase/Instrument/InstrumentHome.aspx" />
</dictionary>
</property>
</object>

And parent definition:

<object id="instrumentPage" abstract="true">
<property name="MasterPageFile" value="~/Web/UseCase/Instrument/InstrumentTemplate.master"/>
<property name="CultureResolver" ref="cultureResolver"/>
<property name="Localizer" ref="localizer"/>
<property name="ScriptsRoot" value="~/Scripts"/>
<property name="CssRoot" value="~/CSS"/>
<property name="ImagesRoot" value="~/Images"/>

<property name="Results">
<dictionary>
<entry key="ErrorCommand" value="redirect:~/Web/UseCase/Instrument/InstrumentError.aspx" />
</dictionary>
</property>
</object>

I want to inherit dictionary Results keys from parent, what can i do?

Regards.

Bruno Baia
05-03-2007, 12:23 PM
Hi,

have you tried using a Spring expression :

<object type="SelectClassSerie.aspx" parent="instrumentPage">
<property name="Results['OkCommand']" value="redirect:~/Web/UseCase/Instrument/InstrumentHome.aspx" />
</object>


- Bruno

magistral
05-03-2007, 02:43 PM
Thanks for the reply.

But throws an exception:

{"Unable to cast object of type 'System.String' to type 'Spring.Web.Support.Result'."}

Looks like when you create a dictionary named "Results" Spring automatically converts the "redirect:" to a Spring.Web.Support.Result object, but not when you set values with indexers. I think that's a little mistake.

If you create a Result object doesn't work either, but i don't like the idea of creating by hand a Result object.

I think spring must automatically create a result object when setting Results property.

Regards.

Mark Pollack
05-05-2007, 02:30 PM
Hi,
This might work. If you define just a get Results property and create the dictionary instance in the constructor, the container will add to the existing collection because it doesn't expose a set property. If a workaround isn't possible, we will add a feature request in JIRA for this functionality.
Cheers,
Mark

magistral
05-15-2007, 03:36 PM
Can you please post an example?

Regards.

Erich Eichinger
05-16-2007, 10:59 PM
Hi guys,

I'm afraid what you are trying to do is not possible at the moment. Even Mark's suggestion of precreating a results-dictionary in the page's constructor won't help.

DI with inherited objectdefinitions is not done definition by definition. First all inherited definitions will be merged into one and the result of merging all inherited definitions will be applied to the resulting object.

Since the "results" property in your "SelectClassSerie.aspx" definition overrides the one inherited from "instrumentPage" you end up with only the results from your "SelectClassSerie.aspx".

To allow this, I guess we would need to change the implementation of

Spring.Objects.Factory.Support.AbstractObjectDefin ition.OverrideFrom(IObjectDefinition other)

to merge individual properties in case of dictionaries or lists.

The only solution I can offer for now is to apply the "instrumentsPage" definition manually by calling

ApplicationContext.ConfigureObject( this, "instrumentsPage" )

from within e.g. your Page.Init() method.

cheers,
Erich

Mark Pollack
07-02-2007, 02:39 PM
Hi,
A JIRA issue (http://opensource.atlassian.com/projects/spring/browse/SPRNET-620) has been created to support collection merging in parent/child object definitions.
Cheers,
Mark