Re: WebObjects and dependency injection (DI)
Re: WebObjects and dependency injection (DI)
- Subject: Re: WebObjects and dependency injection (DI)
- From: Lachlan Deck <email@hidden>
- Date: Tue, 22 Sep 2009 17:56:30 +1000
On 22/09/2009, at 1:18 AM, Henrique Prange wrote:
Andrus Adamchik wrote:
I know it is not the traditional "WO way" of doing things, but from
my experience using a dependency injection container in your app
(Spring, Guice, etc.) is one single thing that you can do to
dramatically improve the design quality, and produce flexible and
maintainable code.
We have been using Guice with WO for some time in our projects. Our
code become easier to test without requiring too much boilerplate
code using a DI container.
Are you able to provide (if you've got time) some more concrete
examples of what was easier?
WO does a bit of that on its own (such as session and application
injection in components), but doesn't bundle a container that a
developer could use for the custom "services" (unlike say Tapestry,
that does have a DI container at its core).
Say I have a WO application and I'd like to use Spring or Guice to
inject custom services in the WOComponents, instead of looking them
up in WOApplication (or worse - defining them as static singletons
somewhere). This sounds easy on the surface. I don't remember all
the component creation internals now (it's been a while since I
poked around the framework code), but I am pretty sure I can create
them with my own factory that is DI container aware. On the other
hand (also because I've been out of the loop on WO for quite some
time), I am sure I am missing some pieces of the puzzle that would
make such setup less practical or outright painful.
Instead of changing component creation internals, we've created an
extension of ERXComponent that obtain the injector and inject the
required members. It is not a perfect solution (you can't use
constructor injection this way), but it is easy to implement.
Why would you want constructor injection for WOComponents?
This and the fact that DI capabilities don't seem to bother the
rest of the community, I figured I'd ask the list on your opinions,
while I am trying to wire this thing up in the background.
So anybody played with DI-on-WO in some form with any success?
We have an audit framework completely based on Guice. We have
created extensions of other important classes to make it possible,
like ERXGenericRecord and ERXEC and we have created a
@WOSessionScoped scope to create/obtain objects per WOSession.
Just a question, Henrique: wouldn't it be better to use an ERXEC
custom factory so that every ec created (even by included frameworks)
are able to be scoped correctly in this sense?
We are planning to create an open source framework with this stuff.
We are just polishing what we've done to use some new features of
Guice 2.0.
Cheers,
Henrique
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
with regards,
--
Lachlan Deck
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden