It sounds like you need a scope: https://github.com/google/guice/wiki/Scopes

Singleton is one form of scope, the servlet extension defines
@RequestScoped which will inject the same instance per-servlet-request
and @SessionScoped
which is per-session

You can also define your own custom scope if these don't fit - however,
writing your own scope is tricky and if you go down that route then you
might want to take a look at Tim's scope helpers in
https://github.com/timboudreau/scopes

On Thu, 25 Apr 2019 at 08:34, rvdalen <rouan.van.da...@gmail.com> wrote:

> 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
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to google-guice@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
> <https://groups.google.com/d/msgid/google-guice/1c1119d5-b836-4e83-a09e-90d859493c5b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@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/CAMr6Z4m66TEZUEgnqOgrHmGo0btuhJB2VBpT0i%2BvbLwm7vfWqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to