ConstructorProperties Question

0 views
Skip to first unread message

Aaron Roberson

unread,
Feb 27, 2007, 2:16:12 PM2/27/07
to lightwire...@googlegroups.com
If I specify ConstructorProperties in the config file should I still
pass in the property to my constructor when calling the object in the
controller?

For example, all of my DAO objects require a DSN to be passed into the
constructor. If I pass in the DSN using the LightWire config property
ConstructorProperties.dsn then I can just do the following in my
controller:

someDAO = application.lightwire.getSingleton("someDAO");
instead of
someDAO = application.lightwire.getSingletom("someDAO").init(application.dsn);

However (and this is my real question), If I leave off the constructor
invocation then my code looks like it doesn't require any values to be
initialized and is not very self documenting. Is that a problem?

What do YOU do in your apps?

Peter Bell

unread,
Feb 27, 2007, 2:32:34 PM2/27/07
to lightwire...@googlegroups.com
Hi Aaron,

You should not call the init() method in your code as LightWire takes care
of the initialization and gives you a single place to put and manage all of
your constructor properties (like DSNs).

One of the main roles of LightWire (or any DI engine) is to take care of
configuration properties, so if someone is looking at a code base using DI,
they will understand that they need to look at the config file for the DI
engine to see the init properties for the objects as when you are asking for
our singleton, you are NOT initializing it, you're just asking LightWire to
do whatever it needs to do to give it to you - fully formed.

Best Wishes,
Peter

Aaron Roberson

unread,
Feb 27, 2007, 5:46:25 PM2/27/07
to lightwire...@googlegroups.com
Thanks for that clarification!

My tought was that if I pulled LightWire out I would have to go back
through the entire application and add .init(#application.dsn#) to
every Gateway and DAO object invocation. That would be a real
headache, not that I would ever go back to not using a DI/ioC
framework.

-Aaron

Peter Bell

unread,
Feb 27, 2007, 6:06:57 PM2/27/07
to lightwire...@googlegroups.com
Hi Aaron,

That is true and something I was talking about a long time ago. If you
implement DI, you *are* dependent on DI because you *aren't* passing all of
the init info you need.

The good news is that you are not dependent on a specific implementation of
DI, so you could replace LW with your own custom DI engine without any
changes to the code other than the initial LightWire.getSingleton() call and
any getTransient calls which by their very nature are factory aware.

However, if it more than adding .init() to object invocations . . . If you
are using DI, you don't HAVE any object invocations within your code.

If you used to have:
Variables.UserService = createobject(whatever).init(whatever)
Userist = UserService.getAll()

Now you just have:
Userist = UserService.getAll()

The invocation disappears completely. The DI engine handles it.

Best Wishes,
Peter

Aaron Roberson

unread,
Feb 28, 2007, 11:21:57 AM2/28/07
to lightwire...@googlegroups.com
> If you used to have:
> Variables.UserService = createobject(whatever).init(whatever)
> Userist = UserService.getAll()

That is exactly how I had it before.

> Now you just have:
> Userist = UserService.getAll()
>
> The invocation disappears completely. The DI engine handles it.

Not exactly. Now I have:

userService = application.lightwire.getSingleton("userService");
qUsers = userService.getAll()

The invocation is still there, just passed off to LightWire's
getSingleton method which invokes the object if it doesn't already
exist. Is there another way of doing it?

Peter Bell

unread,
Mar 2, 2007, 3:31:57 PM3/2/07
to lightwire...@googlegroups.com
Hi Aaron,

Yes there is another way. Inject UserService into your controller (or
whatvere is calling your user service). Not everyone does this, but if you
do, EVERYTHING gets wired up through your DI engine - makes life very nice
indeed!

Best Wishes,
Peter

Aaron Roberson

unread,
Mar 2, 2007, 6:41:51 PM3/2/07
to lightwire...@googlegroups.com
> Yes there is another way. Inject UserService into your controller (or
> whatvere is calling your user service). Not everyone does this, but if you
> do, EVERYTHING gets wired up through your DI engine - makes life very nice
> indeed!

=>=>Wishes Peter Bell would write a blog post on using CFCs for
controllers and some links to some good resources regarding it<=<=

Reply all
Reply to author
Forward
0 new messages