Questions tagged [guice]

Guice is a lightweight dependency injection framework for Java.

Google Guice

Guice is Google's lightweight dependency injection framework. It is an open source software framework for the Java platform, compatible with Java 5 and above, released by Google under the Apache License.

It provides support for dependency injection using annotations to configure Java objects. Guice allows implementation classes to be programmatically bound to an interface, then injected into constructors, methods or fields using an @Inject annotation. When more than one implementation of the same interface is needed, the user can create custom annotations that identify an implementation, then use that annotation when injecting it.

Starting with version 3.0, Guice implements the JSR-330 standard of dependency injection for the Java platform.

References

Related Tags:

3211 questions
1
vote
1 answer

Google Guice: right way to inject primitive data structure

private HashSet childWorkWindows; @Inject public CompositeWorkWindows ( HashSet childWorkWindows ) { this.childWorkWindows = childWorkWindows; } Would Guice know how to inject this automatically without having to specify…
ealeon
  • 12,074
  • 24
  • 92
  • 173
1
vote
1 answer

How to unit test guice createinjector method

I have following main method call where I initialize guice modules using static createInjector method public static void main(String[] args) { Injector injector = Guice.createInjector(Stage.PRODUCTION, new MyServiceModule()); MyService…
mihir S
  • 617
  • 3
  • 8
  • 23
1
vote
1 answer

How to override a TypeLiteral in Scala Guice when testing

In my Module.scala I'm binding a concrete implementation of a trait defined as follows: trait AccessGroupRepository[F[_]] {} @Singleton class AccessGroupRepositoryImpl @Inject()(db: OldDataBase, c: IOContextShift) extends…
sentenza
  • 1,608
  • 3
  • 29
  • 51
1
vote
2 answers

Is it possible to inject implementations for arbitrary types with Guice?

My Issue I am migrating from Tapestry IOC to Guice and I would like to for Guice to forward all unresolved injection requests to Tapestry IOC. This works in the individual case for example: bind(DSLContext::class.java).toProvider (Provider { …
Wulf
  • 393
  • 2
  • 10
1
vote
1 answer

Is it possible to bind an immutable set of certain type to an instance in Guice?

I am a complete beginner with Guice, and trying to achieve the following: public class Apple { private final Integer size; public Apple(Integer size) { this.size = size; } } public abstract class AppleModule { protected…
ozgeneral
  • 6,079
  • 2
  • 30
  • 45
1
vote
0 answers

Managing lifecycle, using Netflix Governator, of java object without Annotations

Is there a mechanism for me to manage the lifecycle of java objects using Netflix governator without the @PostConstruct and @Predestory annotations. I would like to manage the lifecycle of objects within a library that I do not have the power to…
1
vote
2 answers

Making Guice Injector Singleton for Consistency

I was wondering how the injector is typically used. I understand that it's used mainly at start-up time, but how would you use it at run-time to create an object of certain implementation? For example, I have an interface User with implementation of…
juminoz
  • 3,168
  • 7
  • 35
  • 52
1
vote
1 answer

Dependency Injection on Class Instantiated Elsewhere

I am trying to inject ehcache via the Play Framework. I am injecting it into a companion class, but that class is being instantiated in an abstract class elsewhere as well as the companion object. I do not want to inject anything into the abstract…
2b2a
  • 95
  • 1
  • 9
1
vote
1 answer

Guice Scala DI, understanding how

Will default constructor be called in scala if I have @Provides annotation in my Module file to return an object but I never inject it anywhere?
Kumar Kavish
  • 157
  • 1
  • 9
1
vote
0 answers

How to inject generic type to non-generic interface type using Guice

How do I inject generic type to instance of non-generic interface type? for example: I have interface class MessageHandler public interface MessageHandler { public IMessage HandleMessage(String messagePath, String jobId); } I have generic class…
Ammy
  • 11
  • 1
1
vote
0 answers

RestEasy ExceptionMapper is unable to map exception thrown at filter level

The ExceptionMapper implementation works fine for the exceptions thrown at controller level of my code. However there are some authentication filter being executed before and after the api call. Exception thrown at filter level is not being mapped…
Kroor Singh
  • 255
  • 2
  • 7
1
vote
2 answers

Deferred binding to instance using Guice

I have this in my module: @Override protected void configure() { bind(Authenticator.class).toInstance(KerberosAuthenticator.create()); } And the reason for binding to instance here is because Kerberos authentication needs a bit of…
AlexeiOst
  • 574
  • 4
  • 13
1
vote
1 answer

How can i mock Guice Injection using Mockito or any Mocking framework in my Unit Test?

I am trying to write unit test case to test my code with some mockito as mocking framework, In between i came across a problem where in i am unable to mock injection that i made using Google Guice in my test class. I tried Directly injecting the…
Ashutosh
  • 917
  • 10
  • 19
1
vote
1 answer

TestNG - Accessing ITestContext in Guice Module

I was trying to do as per this question. Is there a way to inject ITestContext from TestNg to guice module? Consider this: public class TestParentModule extends AbstractModule { private ITestContext iTestContext; public…
KitKarson
  • 5,211
  • 10
  • 51
  • 73
1
vote
1 answer

function name for @Provides Method in Guice

With @Provides annotation, I am curious what is the function name requirement. @Provides TypeA ProvideTypeA() { ... return TypeA } Is it OK to use a different function name? @Provides TypeA AnyName() { ... return TypeA }
derek
  • 9,358
  • 11
  • 53
  • 94
1 2 3
99
100