Delay initialization support

92 views
Skip to first unread message

jia...@google.com

unread,
Mar 7, 2019, 12:58:39 PM3/7/19
to google-guice
Hi there, 

I have a Guice bean which need to preload some data from Spanner DB after it initialized, but the Spanner DB connection may not been established yet before that bean's binding. I was wondering if Guice allow to post-initialization after all the binding finished. (I know Spring support it)?

Many thanks in advance for the nice help. 

Jian

Stephan Classen

unread,
Mar 8, 2019, 2:19:40 AM3/8/19
to google...@googlegroups.com
You cannot change the configuration of an injector after it has been created.
What you can do is create a child injector which inherits all bindings from its parent and can add extra bindings.

But I think the problem should be tackled by your bean container. Which one are you using. Can you influence the order of bean binding. Why are you using a bean container, would pojos be sufficient...

Bob Lee

unread,
Mar 8, 2019, 11:44:40 AM3/8/19
to google...@googlegroups.com
Inject the Spanner connection into the other class. This will ensure the Spanner connection is established first.

Bob

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/b019b012-3a35-4b71-8cf9-617d3e3b3cb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages