c# - How to get object having constructor as other object in spring? -
i integrating .net application spring. have trouble getting object having constructor object.
my object patterns 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 using:
bar bar = (bar)contextregistry.getcontext().getobject("bar");
i have searched on net , found need add foo in xml can't dynamic per call.
i know spring configuration , here is: in 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>
Comments
Post a Comment