Search code examples
guice

@Inject in guice module


Do we need @Inject over provides___ method in the module class? Eg.

    @Singleton
    @Provides
    @Inject
    A provideA(ExampleClass1<B> example1, ExampleClass2 example2) {
        return new A(example1, example2);
    }

    @Provides
    @Singleton
    @Inject
    B provideB(A a) {
        return new B(new C(a));
    }

In this example, do I need @Inject?


Solution

  • No. @Provides methods do not need the @Inject annotation. Arguments to a @Provides method are already injected automatically.