PDA

View Full Version : The best way to save objects...


dfed
07-21-2005, 09:17 AM
Hi all.

In my project I need to save objects in some container and later to get them. I have found StaticListableObjectFactory which do this. but I want to ask.

Maybe there is an another way?

Rick Evans
07-21-2005, 10:56 AM
Hi Dmitrij

I'm not palming this question off, but in order to answer your question I'd like to get more of a handle on just why you need to save objects into the configuration at runtime.

So... why do you need to save objects into the configuration at runtime? Without obviously going into too much detail, what is the problem that you are trying to solve?

Ciao
Rick

dfed
07-21-2005, 11:33 AM
Ok Rick, I'll try to describe my problem.

There is web-form with some datas. The user press submit button , Spring assemble some object and pass it into project's logic. The logic do something with object's data and return new object which Spring pass to the another web-form.

That'a all...)

Ted Husted
07-21-2005, 12:58 PM
Did you just want to save the object in the client's session container?

* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/050e0924-fd83-45e7-b105-50710538d6c1.asp

Keep in mind that references are being passed. If the business logic make changes to object, the reference in the session will be able to see the changes too. So, you don't really have to pass it around. Once it's in the session, the business logic can change it, and other pages will see the latest version.

HTH, Ted.

dfed
07-21-2005, 01:41 PM
I've thinking that I can use Spring like a container for transporting objects between web-forms...

Rick Evans
07-21-2005, 01:49 PM
Hiya

I would second Ted's answer... if you want to pass objects around between pages, using the session would (generally) be the way to go.

And Ted is correct again in that its references that are being passed aorund and obtained from the container. If you pull and configured object out of the container and subsequently change the values in the object, those changes will be available to other pages (if one is pulling a singleton object out the the container that is).

Ciao
Rick

Ted Husted
07-23-2005, 12:19 PM
I've thinking that I can use Spring like a container for transporting objects between web-forms...

What you might want to do is create your own container, with properties for whatever attributes you need to transport, and store that in the client's session. This way, you don't have a bunch of value objects floating around in the session, and you have a quick-and-easy way to keep track of your session use.

I usually call this a client "Profile" obtject, Aside from attributes to transfer between pages, you can use it to track the client's identity and preferences.

Of course, you can use Spring to deliver up a Profile object when you need to create one, but Spring itself is about manufacturing objects, not storing them afterwards.

HTH, Ted.

Aleks Seovic
08-13-2005, 04:31 PM
I've thinking that I can use Spring like a container for transporting objects between web-forms...

Technically you can, although it will not work for every scenario and it might not be the best solution depending on your needs. As Ted pointed out, Spring is mostly about creating and configuring objects, not about transporting them from page to page.

That said, if your business logic modifies singleton object that is exposed by the Spring container, every page that has that object injected will see the changes. Keep in mind that standard singleton objects have application scope, so once you make any change to an object all users of the application will see new, changed values. If you need to have different state per application user, you will have to add scope="session" attribute to your object definition, which will tell Spring that it needs to create one instance per user, instead of one instance for the whole application.

However, this will only work as long as your business logic is simply manipulating existing objects. If you are creating new objects, you need to use one of the standard ASP.Net mechanisms to transport it to another page -- either by using HTTP session as Ted and Rick suggested, or by storing it within HTTP context and transferring request to your target page.

HTH,

Aleks