sting-ioc / sting

https://sting-ioc.github.io
Apache License 2.0
8 stars 0 forks source link

Add support for @PostConstruct or similar #11

Open realityforge opened 4 years ago

realityforge commented 4 years ago

The way that the @Injector is constructed and the constraints that are applied to the components (i.e. No invoking Supplier types during construction ala #9) will typically mean that it is impossible for a component to access another component before it is constructed.

The one scenario where this is not true is if the construction of a component creates an asynchronous action that invokes a Suppler dependency before the injector has completed initialization. This is not possible in a web browser but is possible in a JRE environment.

The only real safe way to fix this is to move the asynchronous action until after the injector has created the eager components. To do this we could allow the components to specify this post create action with an annotation like @PostConstruct which would be used to initiate any asynchronous tasks.