Re: {LightwireFramework} Re: Handling circular dependencies.

1 view
Skip to first unread message

lagos.tout

unread,
Feb 9, 2008, 3:33:10 PM2/9/08
to lightwire...@googlegroups.com
Hi, Paul.
 
Thanks for responding.
I was just curious for comparison sake with ColdSpring.
I guess I haven't figured out when to use CS over LW, or vice-versa.
Of course, for AOP I'd have no choice but CS.  But for the things they do have in common... ?
Thanks.
 
LT


 
----- Original Message ----
From: Paul Marcotte <pmar...@gmail.com>
To: lightwire...@googlegroups.com
Sent: Thursday, February 7, 2008 3:43:58 PM
Subject: {LightwireFramework} Re: Handling circular dependencies.

Hey LT,

You can use "mixin" injection in Lightwire rather than "setter" injection.   In ColdSpring the way around a circular dependency is to use a property  tag instead of a constructor-arg.  Lightwire has both constructor and setter injection and the aforementioned mixin injection.

I caught your post on the ColdSpring list as well, so I'm curious about you object dependencies.  Do you mind sharing some information about the dependent objects?

Paul

On Feb 7, 2008 3:31 PM, LT <lagos...@gmail.com> wrote:

Hi,

I was wondering if Lightwire handles circular dependencies in a
different way from ColdSpring.
Thanks.

LT.


Paul Marcotte

unread,
Feb 9, 2008, 9:47:35 PM2/9/08
to lightwire...@googlegroups.com
Hi LT,

My pleasure.  To give you a bit more information, you can use a superset of ColdSpring xml definitions with Lightwire.  The difference is that since Lightwire supports mixin injection, there is a <mixin/> tag.  What mixin give you is the ability to reference the dependency as variables.MyMixin without having to add a specific setter for "MyMixin".

But that's where it stops.  You won't find  AOP, Autowiring, or remote proxies with LightWire.

Regarding the circular dependency, I just wanted to mention that many of the community leaders like Sean Corfield and Brian Kotek suggest that having a 1:1 ration of Services to business objects can cause issues like circular dependencies.  Quick example.  Say you have a ProductService and and CategoryService for your online catalog.  If you have a circular dependency between the two, you might consider rolling them up into a CatalogService that provides API methods Products and Categories.  This is a application design paradigm that I'm currently working toward.

So, uh, that's my 2 cents...

Cheers,

Paul
--
Paul Marcotte
Fancy Bread - in the heart or in the head?
http://www.fancybread.com

Peter Bell

unread,
Feb 10, 2008, 12:31:17 PM2/10/08
to lightwire...@googlegroups.com
Also, LW was designed for DI into transients as well as singletons. You *can* do that with CS, but it is not recommended. The recommended solution in CS is to create a factory that’s bean aware for the transient DI (say you have a user that requires a UserDAO).

Oh, and if you want to write a programmatic config file (instead of XML), that can be done in LW but in CS you’d have to write a script to gen your xml and then pass that in.

I just find LW more elegant for my use cases and as I really need AOP or other such features, I believe I can add them to LW while still keeping it really tight.

Best Wishes,
Peter

lagos.tout

unread,
Feb 10, 2008, 1:38:25 PM2/10/08
to lightwire...@googlegroups.com
Thanks, Peter.
Would you mind explaining a bit more what you mean by "The recommended solution in CS is to create a factory that’s bean aware for the transient DI (say you have a user that requires a UserDAO)"  Also, why is injection into transients not recommended with CS? 

Peter Bell

unread,
Feb 10, 2008, 1:54:28 PM2/10/08
to lightwire...@googlegroups.com
If you want to DI into transients using CS, just email to the ColdSpring list, explain what you want to do and ask whether you should use CS to inject into the transients using “singleton=”false”” and if not, what approach they’d recommend. Please don’t mention me or LightWire – seems to piss them off over there :->

Best Wishes,
Peter

lagos.tout

unread,
Feb 10, 2008, 4:57:02 PM2/10/08
to lightwire...@googlegroups.com
:)
ok. i will.
so do you not use factories?
is it not ok (read 'not best practice') to use LW with factories?
thanks.

Peter Bell

unread,
Feb 10, 2008, 5:03:16 PM2/10/08
to lightwire...@googlegroups.com
You can absolutely use LW with factories. However, because LW can act as a simple factory, your “factory” methods can be simpler. I have a UserService.new() that’ll return a new user object, but the entire code for it is:

cfreturn BeanFactory.getBean(“User”);


That returns my User with (say) a UserDAO or whatever else it needs injected already and ready for use.

So, if I want a UserService.getByID(UserID) method, it’ll just be:

var User = new();
User.loadQuery(DAO.getbyID(UserID));
cfreturn User


Obviously if I needed an abstract factory, it’d be a little more code.

Best Wishes,
Peter

Paul Marcotte

unread,
Feb 10, 2008, 5:14:54 PM2/10/08
to lightwire...@googlegroups.com
LT,

Before diving in and asking about transients on the CS list, do a search.  Brian Kotek recently announced a BeanInjector that is designed for singleton injection into transients without the performance hit you get when doing this natively in CS.

Cheers,

Paul

Peter Bell

unread,
Feb 10, 2008, 5:35:17 PM2/10/08
to lightwire...@googlegroups.com
Good point Paul. I knew I’d read something recently and Brian was involved. Definitely check out that posting!

Best Wishes,
Peter

lagos.tout

unread,
Feb 11, 2008, 7:10:04 AM2/11/08
to lightwire...@googlegroups.com

Cool.  Thanks much, guys!
Reply all
Reply to author
Forward
0 new messages