On Wed, Feb 18, 2009 at 04:45:26PM +0000, Christian Helmbold wrote:
> I've read http://cwiki.apache.org/WICKET/spring.html and the corresponding 
> section in "Wicket in Action" about the troubles with serialization of 
> injected services.
> 
> "Dependencies often have references to other dependencies in the
> container, and so if one is serialized it will probably serialize a few
> others and can possibly cascade to serializing the entire container."
> (http://cwiki.apache.org/WICKET/spring.html)
> 
> As
> far as I understand this is not a dependency injection specific issue.
> In either case all referenced objects are serialized recursively. So I
> think I have to take care about serialization not only when using
> Spring or Guice.
> 
> Wouldn't it be sufficient to use a static member to hold a reference to a 
> service? i.e.
> 
> public class SomeWicketComponent{
>   private static MyService service;
>   // ...
> }
> 

How would you intialize these? Would you have a static getter, and force
yourself to remember to always use it? Or would you have a static setter
and centralize the initialization code somewhere else? Either way sounds
ugly to me.

> Remains
> the problem with the injection. To solve this the mentioned website
> suggests several ways. The Application Object Approach seems to be most
> wicket like to me. But as mentioned there it is very verbose. Why not
> simply insert a  method to deliver requested beans into the Application
> class? It would look like this:
> 
> class MyApplication extends WebApplication {
>    private ApplicationContext ctx = new ClassPathXmlContext("context.xml"); 
> // Spring context
>    public Object getBean(String beanName){
>        return ctx.getBean(beanName);
>    }
> }
> 
> Is
> anything wrong with it?

The problem is you'll end up with code like this sprinkled throughout
your app:

  MyService svc = (MyService) MyApp.getBean("myService");

Let's see, where to start...

- it's ugly
- the cast and the bean name can fail in a way that is only detectable
  at runtime
- it ties all your components to your application class
- it's difficult to test, since you need to mock up a MyApp instance for
  your component to work

> I find it much more elegant than to store a
> reference for each bean in in the application class as suggested on 
> http://cwiki.apache.org/WICKET/spring.html#Spring-ApplicationObjectApproach.
> 

I don't find either very elegant.

> Maybe the annotation-based approach is a bit more elegant but I don't like 
> annotations much.
> 

What don't you like about them? Annotations are a tool just like any
other part of the language. A carpenter doesn't use a brick because he
"doesn't like hammers much."

> It
> seems to me, that dependency injection (DI) and wicket is not a dream
> team. Do you use DI with Wicket or do you use the "classic" approach
> like Wicket itself does?
> 

I've been very happy with @SpringBean so far.

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to