Same here, I get my models from the service layer always. I then "lazy
load" in composite objects the first time they are called for. For
instance, the first time I call getCompany on my user object, the user
object asks the contactManager service for it's company object, sets it
in, and then returns it.
I end up running more small single-record queries, but I only get the
data my model needs to use, since theoretically an endless loop of data
loading could occur if I allowed it and I may have only needed the name
So you don't do any dependent object injection at time of
instantiation? This is a dilemma that I have been going through in my
head as well, I am of the same mind. My preference would be for lazy
loading as well. Thanks for the feedback !
I do use auto wiring to inject pieces of my model upon instantiation,
but the only thing I inject on creation are references to my
singletons like services and DAOs.
For instance, my services are injected with the ColdBox beanFactory
(to give it the ability to create beans via getModel()) and
occasionally I will inject a DAO if I return result sets directly from
the service. Also services often are injected with other services
they need to interact with.
My beans (IBOs really) are usually injected with a reference to their
DAO so they can populate themselves. They are also often injected
with another service if they need it to create composite beans to lazy
load themselves. (For instance, my company bean has a reference to
the contactManager service to get address, communication, and user
beans as necessary)
I never use auto wire to inject other transients-- I wait until I need
them to create them. Furthermore, I personally like to get my
transients from the service and parameters are usually required to get
a bean back which is already populated with the correct data. For
instance this simplified pseudo code might exist in my company bean
and would be called the first time I tried to access a company's
variables.address = variables.contactManagerService.getAddressList
The other place I use auto wiring a lot in in my handlers, but my
service are the only part of my model that my handlers ever interact
I hope this helps.
All this being said, this is just how I use auto wiring. It is not
the only way or the right way necessarily, but it works very well for