Matt H
Matt H

Reputation: 7389

Spring.NET Expression that References an Object Definition

I'm trying to reference another object I've defined in a Spring config file from within an expression. Specifically, I'm trying to populate a property with the value of an expression where I call a method and then a property on the object returned from that method.
I've tried the following (names have been changed):

<property name="NullableIntProperty"
          expression="#{Some.Object.Id}.Get().NullableIntValue"/>

where Some.Object.Id is a reference to another object I have defined in a config file such as:

<object id="Some.Object.Id" ... >

but my app fails to start with the parsing exception expecting "COLON", found '}'. I think it's expecting a namespace, but I'm not finding the documentation for this.

I've tried several things, but everywhere I hit a dead end. I originally tried a combination of the MethodInvokingFactoryObject and PropertyRetrievingFactoryObject which we use in other places for non-nullable types, but this fails for nullables that are actually null since Spring sees an object factory returning null as a failure (which it usually is).

Upvotes: 2

Views: 2033

Answers (2)

Marijn
Marijn

Reputation: 10557

You can use the @(object-id-here) expression syntax to retrieve an object from the Spring context using an expression:

<property name="NullableIntProperty"
          expression="@(Some.Object.Id).PropertyOnSomeObject"/>

Upvotes: 3

Jonatan Lind&#233;n
Jonatan Lind&#233;n

Reputation: 1485

Changing # to $ should fix it, I believe.

Upvotes: 0

Related Questions