Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am integrating my .net application with Spring. I have trouble with getting Object with having constructor object.

My Object patterns are like:
C#
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:

C#
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:
C#
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\

XML
<object id="Bar" type="NameSpace.Bar, ProjectName" singleton="false">
       <constructor-arg ref="foo"/>
    </object>

    <object id="foo" type="NameSpace.foo, ProjectName" singleton="false">
    </object>
Posted
Updated 23-Jul-15 4:44am
v2
Comments
Sergey Alexandrovich Kryukov 23-Jul-15 15:03pm    
Not clear. There is no such thing as "without constructor". There is always at least one, but it can be a default one.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900