I am integrating my .net application with Spring. I have trouble with getting Object with having constructor object.
My Object patterns are like:
public class Bar
{
private Foo foo;
public void setFoo(Foo foo)
{
this.foo = foo;
}
public String toString()
{
return "Bar! Foo : \n" + foo;
}
}
public class Foo
{
string Id { get; set; }
string Name { get; set; }
}
My Old C# code:
Foo foo1 = new Foo();
foo1.Id = 1;
foo1.Name= "Object 1, Foo1";
Foo foo2 = new Foo();
foo2.Id = 2;
foo2.Name= "Object 2, Foo2";
Bar b1 = new Bar(foo1);
Bar b2 = new Bar(foo2);
Like without constructor I am using:
Bar bar = (Bar)ContextRegistry.GetContext().GetObject("Bar");
I have searched on net and found that need to add foo in XML but I can't do that as it is dynamic per call.
I know spring configuration and here it is: In my Spring.config\
<object id="Bar" type="NameSpace.Bar, ProjectName" singleton="false">
<constructor-arg ref="foo"/>
</object>
<object id="foo" type="NameSpace.foo, ProjectName" singleton="false">
</object>