When you are using Wirebox mixin injection to autowire properties, dependencies are not injected until after your pseudo-constructor is called. Here is an example that will fail:
component accessors="true" {
property name="myDAO" inject="";
public function init() {
getMyDAO().myMethod();
}
}
This will cause an error since myDAO has not been injected into the component before init() is called. The solution is pretty simple:
component accessors="true" {
property name="myDAO" inject="";
public function init () {
}
public function postInit() onDiComplete {
getMyDAO().myMethod();
}
}
Adding the onDiComplete annotation to the postInit() method tells Wirebox to run the method after it has instantiated the object and injected any dependencies. I did notice that the method must be public which is unfortunate, but it makes sense. This simple example is pretty useless, but in my case I needed to store a query into a singleton on instantiation so this was just the ticket.