wirebox q -- I'd like to modify an object after it...
# box-products
d
wirebox q -- I'd like to modify an object after it is fully created by the wirebox binder, including after onDiComplete; I thought an influence closure would do this, but it runs before onDiComplete; is there an instance creation hook like this? Maybe just somehow mock out onDiComplete itself?
ultimate usecase here is "appendVirtualAttribute" on a quick instance in tests
b
afterInstanceCreation
?
d
ah the old "shoulda read the docs"
b
Your interceptor will fire for ALL instance, so it's up to you to check which instance is being created and then conditionally modify it if needed.
d
yeah all instances of a particular binding is the goal
ah I see, it's per injector. I can make that work. Would be cool if there was a per binding hook for that though.
b
I can see the utility, but it also could be seen as feature bloat since we already have a more generic solution.
Perhaps put in a ticket though to be able to provide an
afterCreation
closure or something to the mapping
The influence closure was really designed to allow you to modify the mapping itself on the fly, and the mapping is really just the "recipe" for how to build the instance.
So in other words, the influence closure is like a recipe card that can auto-tune the amount of eggs in the cake before you cook it, but the afterinstancecreation is like the food prep guy who adds the candles on every finished cake they go out the kitchen door.
s
brad with the programming bakery analogy ftw
d
hm...I think the influence closure is provided the cake, in the above analogy?
Copy code
var result           = influenceClosure( instance = oModel, injector = this );
maybe I misunderstand
b
I was thinking the influence closure ran prior to the instance being done building, but perhaps not
You said this above
I thought an influence closure would do this, but it runs before onDiComplete
Looking at the code however, are you sure that is true?
It does appear to happen very near the bottom of the getInstance() method.
d
pretty sure ... did a writedump "influence" and a writedump "onDIComplete" in target obj... let me do that again ....
b
Now that I look at the code, I'm fairly sure ondicomplete should run prior to the influence closure, just scanning the code
Because onDiComplete should run as part of ther
builder.buildCFC()
call above
Crap, we're gonna need a new analogy... ok the influence closure is no longer a sentient recipe card, it's now an elf on the shelf that pops out of the bag of flour at some unknown time and sticks his finger in the icing. 🧝
s
best coldbox internals thread ever