PDA

View Full Version : Generics with non-system type parameters


dhpirkle
06-12-2007, 12:17 AM
How can I specify a type attribute for an object where the type is a generic type, and I want to pass a non-system type parameter to the generic? If the type parameter is something like int, it's easy:

<object name="test" type="MyClass&lt;int>, MyLib">

If I want to use "MyOtherClass, MyOtherLib" (MyOtherClass from the MyOtherLib assembly) as the type parameter instead of "int", then I run into trouble:

<object name="test" type="MyClass&lt;MyOtherClass, MyOtherLib>, MyLib">

That's treated like a generic with 2 type parameters.

The documentation suggests that you use aliases. That's fine, but I want to have the whole definition captured in the objects section in an xml file outside of app.config, so I don't want to put the aliases in the app.config file, one approach that is mentioned in the documentation.

There's a TypeAliasConfigurer class that is mentioned for defining aliases withinin the objects section. However, this doesn't seem to be called until after the alias needs to be resolved. If I try to use an alias, an exception is thrown without the breakpoint I set in TypeAliasConfigurer is ever being triggered. If I remove the <object> that uses the alias in its type attribute, the breakpoint is triggered. So TypeAliasConfigurer is called, it just seems to happen too late in the spring life cycle to be of any use.

Any suggestions on how to solve this - either using aliases or not?

Bruno Baia
06-25-2007, 12:50 AM
Hi,

So TypeAliasConfigurer is called, it just seems to happen too late in the spring life cycle to be of any use.
Unfortunately yes, the value within "type" attribute is resolved during the parsing process...


I've created an issue in JIRA (http://opensource.atlassian.com/projects/spring/browse/SPRNET-607) for this.


Bruno

Bruno Baia
08-01-2007, 02:08 PM
Hi,

this issue has been resolved.

Give a try to the next nightly build (the next after Spring.NET-20070731-2222.zip) or wait for the RC1.

- Bruno