R – Creating new Objects With SPRING.Net

spring.net

I'm new on spring.net, and I'm tring to create an List<> of objects.
The list is initialized by a loop that calls:

  • IObj obj= (IObj)ContextRegistry.GetContext().GetObject("obj")

  • change object properties….

  • add it to the list…

the problem is : I keep getting the same object every step of the loop
so I get a list of the same object

Best Answer

If your object definitions are not singletons, then you will get a new object each time. Note, by default, singleton is set to true, so you have to explicitly set it to false.

For example, if you are using xml files to configure your objects, set the singleton attribute to false:

<object name="name" type="..." singleton="false"/>
Related Topic