Getting Guice to inject the same instance, without Singleton scope

63 views
Skip to first unread message

rvdalen

unread,
Apr 25, 2019, 3:34:51 AM4/25/19
to google-guice
Hi,

I am trying to learn Guice as part of working with the Play framework.
I have the following setup:

I have a ProjectController class that has the following contstructor:

    class ProjectController @Inject() (repo: ProjectRepository, uow: UnitOfWork)

The ProjectRepository also has a UnitOfWork dependency.

I would like Guice to inject the same UnitOfWork instance into the ProcjectRepository and into the ProjectController,
without having to make the UnitOfWork a singleton.

Is there a way to do this in Guice currently?

Regards
--Rouan


Stuart McCulloch

unread,
Apr 25, 2019, 5:18:19 AM4/25/19
to google-guice

--
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/1c1119d5-b836-4e83-a09e-90d859493c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rvdalen

unread,
May 2, 2019, 12:47:33 AM5/2/19
to google-guice
Thanks Stuart,

I was hoping that I did not have to write my own scope :).
This feature seems like it should be supported by the IoC container out of the box.
Maybe I just don't understand the complexity behind my request :)

I will look into writing my own scope then.

Regards
--Rouan
Reply all
Reply to author
Forward
0 new messages