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

  • Home
  • SEARCH
  • 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 236971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:23:17+00:00 2026-05-11T20:23:17+00:00

Maybe I am just blind, but I do not see how to use Guice

  • 0

Maybe I am just blind, but I do not see how to use Guice (just starting with it) to replace the new call in this method:

public boolean myMethod(String anInputValue) {
    Processor proc = new ProcessorImpl(anInputValue);
    return proc.isEnabled();
}

For testing there might be a different implementation of the Processor, so I’d like to avoid the new call and in the course of that get rid of the dependency on the implementation.

If my class could just remember an instance of Processor I could inject it via the constructor, but as the Processors are designed to be immutable I need a new one every time.

How would I go about and achieve that with Guice (2.0) ?

  • 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-11T20:23:17+00:00Added an answer on May 11, 2026 at 8:23 pm

    There is some time since I used Guice now, but I remember something called “assisted injection”. It allows you to define a factory method where some parameters are supplied and some are injected. Instead of injecting the Processor you inject a processor factory, that has a factory method that takes the anInputValue parameter.

    I point you to the javadoc of the FactoryProvider. I believe it should be usable for you.

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

Sidebar

Related Questions

Maybe I am just falling asleep (or not!), but how can you do this:
Maybe I just haven't figured out the InfoPath paradigm yet, but any links, or
I'am new to extJS and maybe I just don't know the correct strategy, so
Not that it matters strictly, and maybe I just don't yet fully understand how
I'm interested in texture streaming in DirectX but google seems unhelpful. Maybe I just
Maybe I am just over thinking this and need to write some more prototype
Maybe it's just the fact that I've been using http://nodejs.org/ lately, but the lack
I have the following PHP code, but it's not working. I don't see any
I (think I) understand the purpose of dependency injection, but I'm just not getting
Well, not literally, of course, but: I'm new to Flex and I'm trying 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.