RE: [coldbox:11790] Re: Wirebox Mapping DSL - dependencies not injected when using toProivder() or toFactoryMethod()?

Hmm, so to take this example:

map(“Page”).toFactoryMethod(“PageFactory”, “getPageObject”)
.into(THIS.SCOPES.REQUEST)
.noAutoWire()
.property(
name=“ClientObject”,
ref=“Client”
);

So the issue is that when you ask WireBox for an instance of “Page” (which is provided by the PageFactory), it does not contain dependencies that it needs, correct?
And further, PageFactory is not injecting them, you are expecting WireBox to inject them, correct?

Can you show us the parts of the config that define what dependencies you are expecting WireBox to inject to a “page” object?

Thanks!

~Brad

Hi Brad,

You have summarized my problem very nicely (and much more
concisely) :slight_smile:

I don't understand your question, so I'll try to answer it.

My 1st reply would be isn't the .property(
  name="ClientObject",
  ref="Client"
  )
portion of the above code the part of the config you are asking for?

Let me try to give a better overview without going into a bunch of
unnecessary detail:

In my application.cfc, I instantiate the Injector into APPLICATION
scope:

APPLICATION.Injector = CreateObject("component",
"wirebox.system.ioc.Injector").Init(
  binder = "packages.pathway.WireboxConfigBinder"
)

Then, in my legacy .cfm page, when I call something out of Page that
needs Client, I get the error that the ClientObject doesn't exist:
e.g. Site.Page.getClientObject()

Ok, I think I'm understanding you more now. I've never used .property() since I've always favored annotation-based autowiring. but what you have looks correct at first glance.

One thought, ClientObject will be injected by default into the variables scope. Is that where you are looking for it in the Page cfc? "variables.ClientObject"?

Also, can you enable debug logging via the logBoxConfig property of your WireBox config? (I would recommend a simple logbox config with a file appender that captures all log levels) That might provide some insight if WireBox is having troubles resolving all your mappings.

Thanks!

~Brad

Hi Brad,

I appreciate your help. Sorry if it was convoluted. I'll definitely
look into Logbox, it looks like it's included in Wirebox standalone.

I finally got autowire to work this morning (in a scratch app), so I
could try the annotations method as you suggested.

While programmatically injecting dependencies (using .property() on
the mapping in the config binder) into objects created via a factory
method still doesn't seem to work, using annotations will work, *if*
you call injector.autowire() on the object after creating it in the
factory, which I can understand since factories don't use the injector
to create the object after all...

So I'll attempt to get autowire working in my real app and take the
annotations approach with the Page objects.

Thanks!

Jen