Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • 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!

Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic