Skip to content

@ProvidedBy @Singleton doesn't work #251

Closed

Description

@gissuebot

From limpbizkit on September 26, 2008 13:12:47

It should provide a single instance.

The rules for @ProvidedBy and annotations don't need to be the same as for
@ImplementedBy, where scoping conflicts could be problematic. For
@ProvidedBy the scopes don't conflict.

Original issue: http://code.google.com/p/google-guice/issues/detail?id=251

Activity

  1. gissuebot commented on Jul 7, 2014

    @gissuebot
    Author

    From ori.schwartz on July 14, 2011 11:34:55

    also for @RequestScoped. i assume @ProvidedBy doesn't work with any scope annotations and always uses NO_SCOPE?

    a simple junit test is attached.

    Attachment: gist
       ProvidedByScopeTest.java

  2. gissuebot commented on Jul 7, 2014

    @gissuebot
    Author

    From Ben.Manes on September 17, 2013 14:00:22

    Any chance this is fixed in Guice 4.0? Just ran into this for a servlet filter.

  3. birdmanmandbir commented on Apr 27, 2020

    @birdmanmandbir

    From Ben.Manes on September 17, 2013 14:00:22

    Any chance this is fixed in Guice 4.0? Just ran into this for a servlet filter.

    It is still not fixed. I think it is because @Providedby have larger priority than @Singleton?

  4. GedMarc commented on Apr 27, 2020

    @GedMarc

    isn't it an ordering thing?
    @ProvidedBy is a lazy load provider, singletons with providers need to be registered during module creation as a new provided class?
    If you are going eager singleton even more so...

  5. birdmanmandbir commented on Apr 27, 2020

    @birdmanmandbir

    isn't it an ordering thing?
    @ProvidedBy is a lazy load provider, singletons with providers need to be registered during module creation as a new provided class?
    If you are going eager singleton even more so...

    You're right, maybe we need a new provided class to deal with this situation 👍

  6. GedMarc commented on Apr 27, 2020

    @GedMarc

    No I mean there are two types are singletons, -
    But either way the outcome is the same, so you can't use @ProvidedBy for singletons..
    this seems a very by design item.

  7. birdmanmandbir commented on Apr 28, 2020

    @birdmanmandbir

    No I mean there are two types are singletons, -
    But either way the outcome is the same, so you can't use @ProvidedBy for singletons..
    this seems a very by design item.

    When we use @ProvidedBy, bind(Class1.class).in(Scopes.SINGLETON); is required to get singleton
    When we use @Singleton, guice will create a singleton provider to give a singleton,
    So if we both have @ProvidedBy and @Singleton, only @ProvidedBy is used by guice so we can't get singleton without ).in(Scopes.SINGLETON);

    Am I understanding it correctly?

    And I also write more test cases:
    ProvidedByScopeTest.zip

  8. added a commit that references this issue on May 3, 2020
  9. added a commit that references this issue on Apr 21, 2023
    11450e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址