Brian Pontarelli
unread,Sep 10, 2019, 8:26:52 PM9/10/19Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google...@googlegroups.com
Hi everyone,
Not sure how active this group is anymore, but I’m having a very strange problem that I can seem to get to the bottom of. It could actually be the normal behavior of Guice, but I’m guessing it isn’t.
Here’s an example:
Let’s say I have 3 services named ServiceA, ServiceB and ServiceC and then a Controller. The dependencies look like this:
Controller -> ServiceA
Controller -> ServiceB
Controller -> ServiceC
ServiceA -> ServiceB
ServiceA -> ServiceC
ServiceB -> ServiceC
Essentially, ServiceC is being used everywhere. When I create an instance of the Controller, Guice is creating 3 or more instances of ServiceC. In my real-world case, Guice is creating 500+ or more instances of a single service for each request to the application. It seems like Guice should only be creating 1 instance of ServiceC since it is a leaf node in the graph and the graph is being constructed from a single location (Controller).
A bit of additional detail, we are using multi-binders in some places and the classes being bound into the collections do use a number of services.
Anyone have this issue and figure out how to solve it?
Thanks,
— Brian