Wednesday, July 15, 2015

I remember reading it in the Wirebox Ref Card, but I actually ran into an issue with Wirebox dependency injection and a race condition today. I wanted to blog about it just in case you started with Wirebox without reading the documentation end-to-end ;)

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:

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.