[wirebox-1.7] Mapping Properties of Mapped classes eagerly initialized

Might be taking the wrong approach:

binder config() (snippet):

map(“TimeZoneControl”).to(“model.support.TimeZone”).asEagerInit(); // transient object

// generic account mapping

map(“Account”).to(“model.account.TDAccount”)
.parent(“BaseTRANSIENT”)
.property(name=“Settings”, ref=“model.account.TDAccountSettings”)
.property(name=“TimeZone”, ref=“TimeZoneControl”); // transient object

I though that by specifying an eager init directive to TimeZoneControl would mean that when I getInstance(“Account”) that the TimeZone variable inject into it would be initialized and it’s not. The reason I want to do this is because there will be conditions where when an Account object is populated it will NOT have a TimeZone so that injected object instance will not be populated…but I want to be able to ask the TimeZone object inside account if it is valid…which I cannot do unless the object is initialized. I COULD initialize it in the Account object but that defeats the whole point of injecting it in the first place.

Right approach, wrong, better way?

It makes no sense to eagerly init a transient Mike. Because the eagerly inited instance is created and destroyed. So eager init only makes sense for non-transient objects.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Ok…so that helps with what NOT to do…but the problem that remains is how to initialize an injected property that is a mapped class (or not mapped for that matter) without having to code something in the containing class I’m injecting into.

Mike,

WireBox always calles the object’s init() method upon instantiation. So every dependency should be correctly inited unless the object does NOT have an init() method, or you remove the init constructor via the “constructor()” binder object. So don’t understand if that is what you mean.

Yeah, I thought so too. All my cfc’s have an init() and they always return “this”.

After creating and populating “Account”, if I dump it, TimeZone is not in there, like it’s not being initialized…hence the question.

So the error I’m getting is below.

Duh? Bad scope. This works

map(“Account”).to(“model.account.TDAccount”)
.parent(“BaseTRANSIENT”)
.property(name=“Settings”, ref=“model.account.TDAccountSettings”, scope=“this”)
.property(name=“TimeZone”, ref=“model.support.TimeZone”, scope=“this”);