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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:37:24+00:00 2026-06-11T09:37:24+00:00

My project is using Guice as the IOC container responsible for providing dependencies (service

  • 0

My project is using Guice as the IOC container responsible for providing dependencies (service classes) to a large graph of objects (mostly singletons). Sometimes if a dependency fails during construction and this dependency is required by many objects, the failure will occur over and over again adding the exceptions to the Guice ProvisionException.

I can understand the rational for this behaviour as it gives a list of all the errors that occur to save fixing issues piece meal. However, I would like to disable this feature and ‘Fail Fast’, as the repeated failure in this case is resource intensive. Further more the ‘ProvisionException’ contains a list of the same exception.

I do appreciate that this behaviour is symptomatic (smells) of bad practice in the implementation (i.e. resource intensive object creation), but since the dependencies are abstractions for which anyone can provide implementations and plugin using dependency injection there is little defence against it.

What I would like to know is:-

Is there a parameter that enables Guice to exit Injector creation at the first exception?

Any help would be greatly appreciated.

Edit:

@Test
    public void guiceExample()
    {
        Injector injector = Guice.createInjector(new TestModule());
        try{
        IAmANeedyObject instance = injector.getInstance(IAmANeedyObject.class);
        }
        catch (ProvisionException e)
        {
            assertThat(e.getErrorMessages().size(),Is.is(2));
        }
    } 

This test assets two exceptions have been thrown

import com.google.inject.AbstractModule;
import com.google.inject.Inject;

public class TestModule extends AbstractModule {

    @Override
    protected void configure() {
        bind(IWasDesignedWithHonestIntent.class).to(NastyThrowingExample.class);
        bind(IMindMyOwnBusiness.class).to(SomeLucklessObject.class);
        bind(IAlsoMindMyOwnBusiness.class).to(SomeEquallyLucklessObject.class);
        bind(IAmANeedyObject.class).to(LowSelfEsteem.class);
    }
}

interface IWasDesignedWithHonestIntent {}

interface IMindMyOwnBusiness {}

interface IAlsoMindMyOwnBusiness {}

interface IAmANeedyObject {}

@Singleton
class NastyThrowingExample implements IWasDesignedWithHonestIntent {
    @Inject
    public NastyThrowingExample() throws LongSlowAgonisingDeathException {
        throw new LongSlowAgonisingDeathException("I am dying");
    }
}

class LongSlowAgonisingDeathException extends Exception {
    @Inject
    public LongSlowAgonisingDeathException(String message) {
        super(message);
    }
}

class SomeLucklessObject implements IMindMyOwnBusiness {
    @Inject
    public SomeLucklessObject(IWasDesignedWithHonestIntent designedWithHonestIntent) {
    }
}

class SomeEquallyLucklessObject implements IAlsoMindMyOwnBusiness {
    @Inject
    public SomeEquallyLucklessObject(IWasDesignedWithHonestIntent designedWithHonestIntent) {
    }
}

class LowSelfEsteem implements IAmANeedyObject {
    @Inject
    public LowSelfEsteem(IMindMyOwnBusiness iMindMyOwnBusiness, IAlsoMindMyOwnBusiness alsoMindMyOwnBusiness) {
    }
}
  • 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-11T09:37:25+00:00Added an answer on June 11, 2026 at 9:37 am

    Is there a parameter that enables Guice to exit Injector creation at the first exception?

    I’m afraid that don’t, it doesn’t.

    You will have to continue with a code like your example.
    You can always suggest this for the Guice team on their Google Code page.

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

Sidebar

Related Questions

I have started using Guice to do some dependency injection on a project, primarily
I have one project that I have modularized using Google Guice. But now when
I am working on a project using Depedency injection Google Guice Framework. It's possible
I'm using SAS Enterprise Guide 5.1 and I have a project made of 4
The documentation of my project (using Python 3.2) is created with Sphinx (1.1.3) and
In a web project using jsp, I have following requirement Upload a file (say
i have a JavaScript project (using jquery), inside it i draw a canvas by
I write a project using Prism . I have tow modules and this modules
I have a lein project (using cascalog--but that's not particularly important). I'm trying to
I have a project using DynamicJasper to create reports. It works fine so far,

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.