Link Details

Link 100725 thumbnail
User 111696 avatar

By bloid
via googletesting.blogspot.com
Published: Aug 05 2008 / 02:44

So you discovered dependency injection and GUICE and you are happily refactoring and writing new tests for you code until you come across this circular reference.
  • 6
  • 0
  • 1385
  • 418

Comments

Add your comment
User 131196 avatar

Jakob Jenkov replied ago:

0 votes Vote down Vote up Reply

Circular dependencies can be setup cleanly in Butterfly DI Container like this:

beanA = com.myapp.A(b = * com.myapp.B());
config{ $b.setA($beanA); }

when you obtain A it will contain a B, and B will have it's A set on it using setA();

... or you could just have the factory call a static method that wires up A and B correctly for you. No proxies like Guice does... and far better performance. This circular dependency check is according to Bob Lee one of the performance "killers" of Guice, and probably the main reason why Butterfly is so much faster than Guice.

User 110409 avatar

jw8369 replied ago:

0 votes Vote down Vote up Reply

But with Butterfly, B needs to be mutable.,

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (6)



Voters Against This Link (0)