PDA

View Full Version : Constructor overload resolving with XmlObjectFactory


Great
09-15-2006, 05:42 PM
I am trying to use the GetObject method of the XmlObjectFactory class, but I am having an issue with it resolving the correct constructor.


function object Getobject(string objectId, IDataRecord dr)
{
XmlObjectFactory factory = new XmlObjectFactory(new FileSystemResource("C:\\somepath\\config.xml"), false);
object[] args = { dr };
return factory.GetObject(objectId, args);
}

This method is being called using a SQLDataReader.

My constructors look like this.

public Object(DataRow dr) : base(dr)
{
}
public Object(IDataRecord dr) : base(dr)
{
}
public Object()
{
}


Instead of the constructor having with the IDataRecord being resolved, the empty constructor is resolved.

I would expect the IDataRecord constructor to be used since SQLDataReader implements IDataRecord.

Please give me some insight to what needs to be done to resolve the IDataRecord constructor.

Bruno Baia
09-18-2006, 10:02 AM
Hi,

Can you show a configuration exemple from the "C:\somepath\config.xml" file ?


-Bruno

Great
09-18-2006, 02:42 PM
Thanks for the response.

The config file is fairly simple, and here is an example.


<objects>
<object id="ObjectId" type="Name.Space.Object, Name.Space" singleton="false">
<property name="Name" value="Value"></property>
</object>
</objects>

I would also like to add that the DataRow and blank constructors work as expected. Just the IDataRecord does not resolve correctly.

Bruno Baia
09-18-2006, 03:41 PM
Hmmm,

I'll investigate this.
Matching is done by type, and it seems that the test is "requiredType == providedType" and it should be "requiredType.IsAssignableFrom(providedType)" or something.


-Bruno

Bruno Baia
09-19-2006, 10:50 AM
Hi,

I found the bug and i created an issue in JIRA (http://opensource.atlassian.com/projects/spring/browse/SPRNET-368).

The next nightly build will contain the fix, but if you can't wait until tomorrow, here is the fix :

In the Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.AutowireConstructor(string, RootObjectDefinition, object[]) method (line 1043), replace :

resolvedValues.AddGenericArgumentValue(args[i], args[i].GetType().FullName);

by

resolvedValues.AddGenericArgumentValue(args[i]);



-Bruno

Great
09-21-2006, 02:36 PM
I just downloaded last night's build, and it seems to resolving the SqlDataReader as a IDataRecord now.

Thanks for the help.