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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:01:16+00:00 2026-05-31T04:01:16+00:00

I have an UI component that will be used in several UI module in

  • 0

I have an UI component that will be used in several UI module in an application.

I would like to annotate the UI component that to be injected into several other classes in one UI module to be a singleton, but not a singleton across the whole application. So that for each UI module use the UI component, one and only one of the UI component instance is used.

I couldn’t find a straight solution for this from the Guice document. So i think maybe I can use annotation to distinguish those instance?
Say in Module A, I annotate all the injection of the UI component with Named("ModuleA"); and in Module B, with Named("ModulaB"). and in the configuration, i tried to use something like:

this.bind(UIComponentA.class)
    .annotatedWith(Names.named("ModulaA"))
    .to(UIComponentAImpl.class).in(Singleton.class);

this.bind(UIComponentA.class)
    .annotatedWith(Names.named("ModulaB"))
    .to(UIComponentAImpl.class).in(Singleton.class);

Because UICompoenetAImpl also need to be injected, so I couldn’t simply create the instance there. Totally not sure if this works.

And I’m wondering what’s the standard way to accomplish this?

  • 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-31T04:01:18+00:00Added an answer on May 31, 2026 at 4:01 am

    One other option might be to use a child injector for each module.

    This would allow you to bind a difference instance of UIComponentA in each module. Bind them in the child injector rather than the parent. You would then need to make sure that all of your module’s dependencies are built from the right child injector, probably by making sure the root of each module is loaded from the right place.

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

Sidebar

Related Questions

I have an application that requires resizing of a component that will be scaled
i have several common elements (components), that will generate some html. it seems my
I'd like to have a TabNavigator component that has a close button for some
We have a legacy VB6 component that was com+/MTS and is used by asp
I have a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was used only
I have several properties related to the configuration of my app that I'd like
For a .NET component that will be used in both web applications and rich
I have a database component that relies on AsyncTask to retrieve data. Once used
We have a piece of functionality that is used by several different applications (clients)
We have had a web application product for several years, and used Tomcat to

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.