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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:21:01+00:00 2026-05-17T16:21:01+00:00

I created a class that uses the the Java Executor API to create/manage a

  • 0

I created a class that uses the the Java Executor API to create/manage a pool with fixed number of threads.
Each thread needs a new instance of a particular object, and I would like to inject this object with Guice.
For the moment I’m using a Provider which provides new instances of the object through its get() method.

But now this class has a dependency to the Provider, which is Guice specific, effectively coupling the code to the Guice framework.
I would really like the class to be truly Guice agnostic, is this possible?

Just creating new instances of using the ‘new’ keyword is not an option, as this makes it impossible to replace those object by a mock implementation in the unit test.

Dependency injection is probably not suited for this and I would be better of creating a factory to get these objects?

  • 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-17T16:21:01+00:00Added an answer on May 17, 2026 at 4:21 pm

    One thing you may want to consider is building Guice from trunk and using that until Guice 3.0 is released. Then you can use JSR-330‘s javax.inject.Provider instead of Guice’s.

    Edit: Other than that, I’m generally of the opinion that coupling to the DI container (by importing something from com.google.inject, in this case) is less of an issue than people sometimes make it out to be. As long as you aren’t depending on the details of how you get your dependencies (e.g. injecting the Injector all over the place) it’s fairly easy to, say, change all places you injected Provider to take your own interface with a similar function instead. Depending on powerful features like scoping is where you really couple yourself to the container. I think that’s fine as well though, given how much ugliness and effort they save you.

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

Sidebar

Related Questions

Is there any easy way to create a class that uses IFormatProvider that writes
If you create a class library that uses things from other assemblies, is it
I need to create at runtime instances of a class that uses generics, like
I have a collection of classes that inherit from an abstract class I created.
For a new project that I'm doing in PHP I've created an SQLMethods class
I've created a method that generates a new class and adds some methods into
I have a control that is created like so: public partial class MYControl :
I would like to create a class that creates and manages log files. I
When I create utility classes I typically create a class that has a private
A common pattern in C++ is to create a class that wraps a lock

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.