Creating new objects with SPRING.Net
I am new to spring.net and I am trying to create List <> objects. The list is initialized with a loop that calls:
-
IObj obj = (IObj) ContextRegistry.GetContext (). GetObject ("obj")
-
change object properties ....
-
add it to the list ...
the problem is this: I keep getting the same object at every step of the loop so I get a list of the same object
If your object definitions are not single, you will get a new object each time. Note that the default for singleton is true, so you must explicitly set it to false.
For example, if you are using xml files to customize your objects, set the singleton attribute to false:
<object name="name" type="..." singleton="false"/>
a source to share
It is not clear what you are trying to achieve by going over the GetObject ("obj") method. Maybe you can post the code for the loop?
What "GetObject (" obj ")" is to ask for a container for an object named "obj". You indicated that you want to change the properties of the object and add it to the list. This is what the container can do for you: Set object properties: http://www.springframework.net/doc-latest/reference/html/objects.html#objects-simple-values Create list: http: // www. springframework.net/doc-latest/reference/html/objects.html#objects-collections-values
This list can be entered into the selected object.
If you just want the non-lone objects of your IObj, naders's answer is correct. Spring calls these non-single "prototype" objects. An overview of the scopes available can be found here: http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-scopes
a source to share