I apologize if this is an already answered question. I'm not able to
find info on it.
My goal: delay construction of an object for which the class name will
differ depending on the page requested while still taking advantage of
the Injector on the constructed object. This is legacy code, so I have
been using the Wirebox Mapping DSL.
I have been playing around with various methods. But I keep running up
against 2 problems: either the object gets constructed too soon, or
the dependencies are not injected into the object.
I understand why most of the problems are occurring, but the solution
that boggles my mind is the following:
I was expecting the following behavior: Site calls the virtual
provider, PageProvider.get(). The virtual provider calls
injector.getInstance() via the ScopeStorage collection, which would
essentially call PageFactory.getPageObject(), which determines the
class path and calls CreateObject(). Then I'd assume the injector
would continue along its merry way of injecting the dependencies into
the Page object.
However, this last step, the dependency injection, is not occurring. I
get a "ClientObject does not in exist" error (to paraphrase).
I have also tried a solution such as making PageFactory a custom
provider and calling map("Page").toProivder("PageFactory"), but in
that instance if I call PageFactory,get() in Site, the same missing
dependencies problem occurs, while directory injecting Page into Site
causes the construction of Page to happen when Site is constructed...
I also tried injecting the Injector into PageFactory and fiddling with
injector.autowire() in various ways that I won't belabor.
Okay, so do I have to just give up and inject the dependencies into
Page via PageFactory? Obviously that will work, but I guess the bigger
question is are dependencies injected when using toFactoryMethod()...