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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:07:45+00:00 2026-06-17T17:07:45+00:00

The use case I have is this: An object requests a unbound @Named injection

  • 0

The use case I have is this:

An object requests a unbound @Named injection of a specific type. I want Guice to tell my ‘fallback’ provider what the name value was (or give me the entire annotation) so my provider can still provide an implementation based on the name value.

The @Named value is thus used as a key to find the correct implementation at runtime. If an implementation is found based on the @Named, then the provider should not be consulted.

  • 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-17T17:07:46+00:00Added an answer on June 17, 2026 at 5:07 pm

    Guice is basically a map from a (annotation, type) tuple to a Provider<T>. There is no more a way to bind a default binding to all unbound @Named instances than there is to bind an entire range of doubles to a single string in a Map<Double, String>.

    If you have a convenient array or Collection of all @Namedvalues you want, you could loop through them and bind them all to some kind of default provider, which you could then hack using Modules.override() or an if block within the loop:

    public class DefaultNameModule extends AbstractModule() {
      @Override public void configure() {
        for (String name : YOUR_LIST_OF_NAMES) {
          if (properties.contains(name)) {
            bindConstant(properties.get(name)).annotatedWith(Names.named(name));
          } else {
            bind(Foo.class)
                .annotatedWith(Names.named(name))
                .toProvider(new MyProvider(name));
          }
        }
      }
    
      private static class MyProvider extends Provider<Foo> {
        final String name;
    
        MyProvider(String name) {
          this.name = name;
        }
    
        @Override public Foo get() {
          return someValueBasedOn(name);
        }
      }
    }
    

    If this is too complex for your taste, remember that you can always inject an instance of a one-method object that wraps the Properties access for you, calculating a default if needed.

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

Sidebar

Related Questions

I have this use case of an xml file with input like Input: <abc
My use case is this... I have a project that has two production branches.
I have a use case with NServiceBus explained in this question. Essentially there is
I have the following use case for my Tornado web server: Upon POST requests
I'm just starting to learn AspectJ, and I have use-case for say, User login.
I have following use-case: there are several assemblies decorated with ProtoContract classes and I
I have a use case where I need to call a (non-static) method in
I have a use case where I am setting the page focus to a
I have a use case where if a number lies between 0-10 it should
I have the following use case: There's a class called Template and with 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.