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
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"/>
It is not clear what you are trying to achieve by looping over the "GetObject("obj")" method. Maybe you can post the loop-code?
What "GetObject("obj")" does is to ask the Container for the Object with the name "obj". You stated that want to change the object's properties and add it to a list. This is something the container can do for you:
Set the properties of an Object:
http://www.springframework.net/doc-latest/reference/html/objects.html#objects-simple-values
Create a list:
http://www.springframework.net/doc-latest/reference/html/objects.html#objects-collections-values
This list can be injected into an Object you choose.
If you just want non-singleton objects of your IObj, naders answer is correct. Spring calls these non-singleton objects "prototypes". An overview of available Scopes can be found here: http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-scopes
Related
I am very confused about something and I would appreciate some insight here.
Say I want to build a GUI that visualizes what is going on inside JShell, i.e. how the, by snippets created objects reference each other and what, by Snippets created objects are contained inside my running instance of JShell. How do I access these objects, and most of all, how do I access how they reference each other?
A concrete example: I create a JShell instance, pass it a few snippets created by the user, which cause the creation of, for example, an ArrayList, a few objects, and add said objects to said ArrayList.
How do I access this ArrayList and the objects contained within it to visualize this in a GUI?
To clarify further:
//say I create a Jshell:
JShell jShell = JShell.create();
//Which then evauletes user code passed from the GUI:
jShell.eval(userCode)
//userCode could be following lines each passed as separate Strings:
“ArrayList<TestObject> allObj = new ArrayList<TestObject>();”
“TestObject tst = new TestObject();”
“TestObject tst2 = new TestObject();”
“allObj.add(tst);”
“allObj.add(tst2);”
How do I access “allObj”?
How do I access “tst” and the object it points to? (the “TestObject”instance that “tst” points to);
I know eval() returns a list of SnippetEvents which contain the changed/added snippets, however, I can’t get my head around how to access the objects created by those snippets.
Assuming your classpath has access to the TestObj you could implement Serializable on that object. Upon completion of the eval run another method automatically that serializes the output. Then you can deserialize that object inside your code.
I'm trying to create a MutableProperty which holds a Results received from Realm.objects(_:).
To create the property I need to give it an initial value; hence an 'empty' Results.
I've tried creating one using:
var someThings = Results<SomeObject>()
MutableProperty(someThings)
But the compiler gives me the error: Cannot invoke initializer for type 'Results<SomeObject>' with no arguments.
While I understand the error, I'm not really sure how to create a Results object in this context.
Looking at the source of Results I couldn't find an init either.
So my question is; how can I create a Results myself to use in a MutableProperty?
Edit:
I've seen this question...but that doesn't really help (unless I'm going to create a "wrapper" for the MutableProperty or something).
With help of the comments on my OP; I created a mutable property with an empty set of results by fetching objects with an 'invalid' filter.
E.g. MutableProperty(realm.objects(SomeObject.self).filer("EMPTY SET")).
I have an question about binding:
I have an array of objects of my custom class: Array. Every object can be updated (change his properties value) in bg.
Also I have separated Controller, which take and store one object from list as variable and can update it (object still the same, so in list it will be updated too)
Is there any way to bind all object.property -> UILabels on Controller in way, when property changes automatically call label update?
Of course, there are multiple ways how to do it, but from your description I would use some kind of subject (because u said there will be changes in background so you will probably need hot observable )....For example Variable or PublishSubject. So you can crate
let myArrayStream: Variable<[MyObject]> = Variable([])
you can pass this variable as dependency to wherever you want, on one side you can subscribe to it, on the other side you can update it's value.
I have a subclass of PFObject called Session. This object stores an array of objects as an instance variable. The array contains objects of type Event, which is also a subclass of PFObject. When I call the pinInBackground on the Session object to cache it locally, will this array instance var also get cached? I understand that caching standard PFObjects stores the data dictionary, but what about subclasses?
Based on the comment from #lightice11 above, I realized that this can be achieved by marking instance vars as #NSManaged, and they will be saved in the Parse Local Datastore.
Make sure you've added the #NSManaged tag to the variable.
Parse will then automatically save changes to the variable, but it does not have a default value. This can be solved in many ways, some of which I outlined here.
Is it possible to use the Searchable Plugin to create an index of objects and never actually save the objects to the database?
I think so. If you never save the objects, then I think you can just call:
domainInstance.index()
But I've never tried it, so I'm not sure if it just indexes the one instance, or any instance of that class.
See here:
https://svn.codehaus.org/grails-plugins/grails-searchable/trunk/src/groovy/org/codehaus/groovy/grails/plugins/searchable/compass/domain/DynamicDomainMethodUtils.groovy
If you just want to save the object but just want to index manually, then set the following in your conf/Searchable.groovy config file:
mirrorChanges = false
bulkIndexOnStartup = false
See here: https://svn.codehaus.org/grails-plugins/grails-searchable/trunk/src/conf/Searchable.groovy