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 7680203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:03:41+00:00 2026-05-31T18:03:41+00:00

I have two interfaces A and B and B is extending A. I have

  • 0

I have two interfaces A and B and B is extending A.

I have one provider being able to provide instances whose Class is implementing B (and consequently A).

I would like to bind Provider to B.class (straightforward) and to A.class with an Annotation in a singleton scope.

bind(B.class).toProvider(MyBImplProvider.class).in(Scopes.SINGLETON);
bind(A.class).annotatedWith(Names.named("B")).toProvider(MyBImplProvider.class).in(Scopes.SINGLETON);

How to return the same instance from the provider no matter if I inject through B.class or through A.class+Annotation. For instance, I’d like to be able to define constuctors as

@Inject
C(B param)

or

@Inject
C(@Named("B") param)

In both case, I’d like param to be valuated with the same singleton.

  • 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-05-31T18:03:42+00:00Added an answer on May 31, 2026 at 6:03 pm

    How about making your A Provider depend on the B provider you’ve defined above?

    @Provides 
    @Named("B")
    A provideA(Provider<B> bProvider) {
      return bProvider.get();
    }
    

    That should work since you said B extends A. You might need to play around with the @Named bit.

    Another option would be to use a toInstance(yourObject) binding. But this makes it messy to inject any dependencies into that object. You would have to use Binder#requestInjection().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Java interfaces and one implementing class. (I have used Eclipse to
I have a class that instantiates two classes which implement interfaces. I want one
In my system I have two different projects, one defining its interfaces and another
I want to have two separate interfaces to my website, one that is silverlight,
I have two questions regarding interfaces in Java. 1) If a class happens to
I have two options in VS2010 for implementing interfaces. When I have IHelper.cs interface
Straight to the problem: I have a class that implements two interfaces: public class
I stumbled upon a documentation where COM objects have two kinds of interfaces, one
I have two basic interfaces as below, one inheriting the other. I am binding
I have two interfaces IHeaderRow , and IDetailRow I then have an object that

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.