-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Rob note:
This issue has been translated into: "@PreDestory order should be reverse of bean registration/construction order"
... so not related to @PostConstruct order per se.
Note that the "registration/construction order" is typically determined based on constructor dependencies. So we can think of this as ... "based on constructor dependencies, the @PreDestrory order now defaults to the reverse order of that [we can almost consider this a BUG fix]. ".
We then use explicit priority to control the exact @PreDestory order as necessary beyond that.
Running the demo app (https://github.com/avaje/avaje-inject-examples/blob/main/modular-coffee-app) with added println() produces the following output:
ElectricHeater:constructor() Thermosiphon:constructor() MainWithNo:constructor CoffeeMaker:constructor() ElectricHeater:init() Thermosiphon:init() CoffeeMaker:init() Aug 07, 2025 1:20:53 PM io.avaje.inject.spi.DBeanScope start INFO: Wired beans in 24ms CoffeeApp:BeanScope ~~~heating core ElectricHeater ~~~ => => pumping core Thermosiphon => => as [_]P Coffee [_]P ElectricHeater:close() Thermosiphon:close() CoffeeMaker:close()
However, using the C++ analogy, the destructors should run in the reverse order of constructors. If ElectricHeater and Thermosiphon were services used by multiple Makers, the Makers should have been flushed and closed before shutting down the Makers, or the Makers could not have finished processing cleanly.