Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9320215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:34:53+00:00 2026-06-19T03:34:53+00:00

If I have a module like this: public class MyModule extends AbstractModule { @Override

  • 0

If I have a module like this:

public class MyModule extends AbstractModule {
    @Override
    public void configure() {
        bind(WhatsThis.class).to(AnAppleOfGold.class);
        bind(TellMeYourName.class).to(Bosse.class);
    }

    @Provides
    public AnAppleOfGold providesApple() {
        return new AppleOfGold(providesFizz());
    }

    @Provides
    public Bosse providesBosse() {
        return new Bosse("Grab a hold of my beard", providesFizz());
    }

    @Provides @Singleton
    public Fizz providesFizz() {
        return new Fizz(Math.random());
    }
}

Every time Guice uses providesApple and providesBosse to inject AnAppleOfGold and Bosse objects respectively, do they get the same singleton instance of Fizz? In other words, does Guice honor scope between provides methods, or does it only honor scope (in this case, Scopes.SINGLETON) from “outside” the module (the DI client code)? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:34:54+00:00Added an answer on June 19, 2026 at 3:34 am

    Guice will honor Singleton scope between @Provides methods, providing that Guice is the one calling them.

    In your example, you call providesFizz() manually, which works just like any other method call. Guice will inject a new instance each time you try to get a new AnAppleOfGold or Bosse. Meanwhile, it will create a separate new instance when you request a Fizz through Guice, and return that same instance for every Fizz injected through Guice.

    So how do you access the common instance from other @Provides methods? Simple: Guice will inject all parameters on your @Provides method, including Fizz or Provider<Fizz>.

    @Provides
    public AnAppleOfGold providesApple(Fizz fizz) {
      return new AppleOfGold(fizz);
    }
    
    @Provides
    public Bosse providesBosse(Provider<Fizz> fizzProvider) {
      return new Bosse("Grab a hold of my beard", fizzProvider.get());
    }
    
    @Provides @Singleton
    public Fizz providesFizz() {
      return new Fizz(Math.random());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program like this. Module Module1 Public Class Mstr Public Property Prop1
I have a method in a url rewriting module that looks like this public
Suppose I have objects that have a parent-child relationship like this: public class Node
My Guice configuration looks something like: public class SocialServiceGuiceConfig extends GuiceServletContextListener { @Override protected
I have a custom module. Migrations.cs looks like this. public int Create() { SchemaBuilder.CreateTable(MyModuleRecord,
So I have something like this: module top (..., out,...); ... output [0:1] out;
Let's say we have code looks like this module TM def aa puts aa
I have a setup like this. var element = $(.module-panel, this.el); $('.module-panel:not('+element+')').hide(); What I'm
I builded a RibbonGroupBox like this in a C# file: public class TextControl :
I have a service contract interface that looks like this: [ServiceKnownType(typeof(GeometricModelDescriptor))] [ServiceKnownType(typeof(TemplateModelDescriptor))] [ServiceContract] public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.