|
From: Brian M. <br...@ap...> - 2004-09-20 19:00:49
|
I may be wrong in thinking that this doesn't exist in Spring, if I am,
please tell me! I cannot find anything though.
In the SpringMVC configurator I would like to have scope BeanFactory
instances. One, as currently, in the application scope, one in the
session, and one in the request. Each factory would have the higher
scope as its parent.
The primary reason for this is that I would like to have strongly typed
session scoped components.
public class ThrowAwayFooController
{
private BarComponent bar;
public void setBarComponent(BarComponent bar) { this.bar = bar; }
public void doStuff() {
bar.setSomeSessionData("wombats!");
}
}
would sit in the request scope factory as a singleton, the BarComponent
(following)
public class BarComponent
{
private String animalType;
public void setBarComponent(BarComponent bar) { this.bar = bar; }
public void setSomeSessionData(final String animalsType) {
this.animalType = animalType;
}
public String getAnimalType() { return animalType; }
}
would be in the session scope factory.
Later throwaway controllers could also be dependent on BarComponent and
receive the same one.
This provides a much cleaner way of handling session state than using a
flat map, I think. It also allows you to change component scopes by
simply moving them to a different factory -- presuming the hierarchy is
respected, nothing changes (say a stateful thing becomes stateless so
can be moved to the application scope, or vice versa).
Thoughts?
-Brian
|