Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Q for Dhanji - DI disadvantage

Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dhanji,

So from what I understand about DI with my past experiences is that the dependency you inject is FIXED, so if the object moves from one VM to the other - you are in pretty much messed up state in trying to re-work the dependencies and it's injection.

While comparing it to a JNDI service - it will be able to locate the object irrespective of the location of the object on the subnet.

Do you think this is one of the biggest weaknesses of DI Patter or are there any bigger issues and workarounds if any?

Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for your question it is quite interesting. Actually I don't see that as a limitation. An object obtained from JNDI and serialized on the wire will still have the same problem you describe.

The correct solution is of course to *always* obtain the object via JNDI. However, this means you have to go through some contortions to serialize services. With the injector this is solved by using what we call "Static" injection in Guice. When an object is brought out thru the wire you can statically repopulate it with deps during deserialization.

This pattern is discussed in some detail in the Guice forums, but essentially it is not a limitation of DI as such. And more a problem about transmission across the wire. In general, I would not send services across the wire anyway, but separate their state into value objects which are easier to transmit and do not hold references to instances in a particular VM.

Hope that helped!

Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic