guice

Guice call init method after instantinating an object

Is it possible to tell Guice to call some method (i.e. init()) after instantinating an object of given type? I look for functionality similar to @PostConstruct annotation in EJB 3. ...

JSF, Exception Logging using a aopalliance MethodInterceptor

I would like to log the exceptions that are thrown when serving JSF files in the same way other exceptions are logged in our web application. We annotate classes with logged exceptions with @LoggedExceptions and a MehtodInterceptor is matched against those classes with Guice AOP (This should be very similar for other implementations of ...

Implementing dynamic plugins in Java

I'd like to implement a dynamic plugin feature in a Java application. Ideally: The application would define an interface Plugin with a method like getCapabilities(). A plugin would be a JAR pluginX.jar containing a class PluginXImpl implementing Plugin (and maybe some others). The user would put pluginX.jar in a special directory or se...

Constructor Injection using Guice

I have some sample code which is using factories. I'd like to clean up the code by removing the factories and use Guice instead. I attempted to do this but I hit a small roadblock. I am really new to Guice, so I am hoping someone can help me out here. Existing client code (Using factories): public class MailClient { public static ...

Where to keep guice injectors?

What is your advice? I found most suitable for me solution - keep injectors and modules in enumeration classes. Advantages: injectors and modules created once, injectors can be used from different classes while running application (not only at bootstrap), injectors kept in one place and can be easily found. Example: import static r...

How to inject Injector?

Situation: i need lazy dependency instantiation in some FooClass, so i pass Injector to class as a constructor parameter. private final Injector m_injector; public FooClass(@Named("FooInjector") Injector injector) { m_injector = injector; } But guice doesn't permit to bind core classes (injectors, modules and etc). What is the soluti...

Using a URL exclusion pattern / Running App Engine in dev mode with Guice.

I'm using GAE and Guice, but I'm running into problems on the dev server. This is my web.xml <filter> <filter-name>guiceFilter</filter-name> <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> </filter> <filter-mapping> <filter-name>guiceFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> Everyt...

Is it wrong to make every concrete class to inherit from an interface ?

This is in response to certain comments made by Zed Shaw in his blog a long while ago. The experts will then saunter off to implement their Flaming Tower of Babel without any comments, horribly complex mock enabled tests, making sure EVERY SINGLE CLASS HAS AN INTERFACE, and ending every class with “Impl” because, well, th...

What problem does Peaberry for Guice solve?

I understand the problem that OSGI solved thanks to this question.... http://stackoverflow.com/questions/106222/what-does-osgi-solve And I am already convinved that Guice is amazing so I'm curious what this OSGI integration for Guice known as "peaberry" is supposed to do, it seems to be popping up everywhere, even in Maven 3 presentati...

Guice, JDBC and managing database connections

I'm looking to create a sample project while learning Guice which uses JDBC to read/write to a SQL database. However, after years of using Spring and letting it abstract away connection handling and transactions I'm struggling to work it our conceptually. I'd like to have a service which starts and stops a transaction and calls numerou...

Injection with google guice does not work anymore after obfuscation with proguard

Has anyone ever tried to combine the use of google guice with obfuscation (in particular proguard)? The obfuscated version of my code does not work with google guice as guice complains about missing type parameters. This information seems to be erased by the transformation step that proguard does, even when the relevant classes are exclu...

GWT Acegi alternative

I'm starting new project. The client interface is based on GWT (and GXT) I have no say it's predetermined. However I can pick and choose as far as server side so I can have some fun and hopefully learn something new in the process. Some requirements are : Exchange with server will be through use of JSON, most if not all of UI will be g...

How to do manual DI with deep object graphs and many dependencies properly

I believe this questions has been asked in some or the other way but i'm not getting it yet. We do a GWT project and my project leader disallowed to use GIN/Guice as an DI framework (new programmers are not going to understand it, he argued) so I try to do the DI manually. Now I have a problem with deep object graphs. The object hierar...

Using Grapher on GIN application with GinModuleAdapter

I've been trying to use Grapher on my GIN project. But trying to create an Injector to give the InjectorGrapher has not been working. Right in the first line of my code: Injector injector = Guice.createInjector( new GinModuleAdapter( new MyGinModule() ) ); it crashes with Exception in thread "main" java.lang.AssertionError: sho...

How test guice injections?

I gave to Google Guice the responsability of wiring my objects. But, How can I test if the bindings are working well. For example, suppose we have a class A which has a dependence B. How can I test than B is injected correctly. class A { private B b; public A() {} @Inject public void setB(B b) { this.b = b ...

What is the correct stage to use for Google Guice in production in an application server?

It seems like a strange question (the obvious answer would Production, duh), but if you read the java docs: /** * We want fast startup times at the expense of runtime performance and some up front error * checking. */ DEVELOPMENT, /** * We want to catch errors as early as possible and take performance hits up front. */ PRODUCTION...

How do you create a non-Thread-based Guice custom Scope?

It seems that all Guice's out-of-the-box Scope implementations are inherently Thread-based (or ignore Threads entirely): Scopes.SINGLETON and Scopes.NO_SCOPE ignore Threads and are the edge cases: global scope and no scope. ServletScopes.REQUEST and ServletScopes.SESSION ultimately depend on retrieving scoped objects from a ThreadLocal...

Is it a good or bad practice to call instance methods from a java constructor?

There are several different ways I can initialize complex objects (with injected dependencies and required set-up of injected members), are all seem reasonable, but have various advantages and disadvantages. I'll give a concrete example: final class MyClass { private final Dependency dependency; @Inject public MyClass(Dependency de...

Using Guice to inject dependencies into an Android activity's constructor

Does anybody know of a way to use Guice to inject dependencies into the constructor of an Activity in Android? It looks like activities normally have only the default constructor so that the platform can easily create a new instance. While it is easy enough to have a singleton to reference the injector and get dependencies that way it ...

What's the most minimal way to achieve Dependency Injection?

I've been reading about Spring and although it's claimed to be a less complex alternative to EJB, I'm having a hard time wrapping my head around it. Is there a more minimal way of achieving Dependency Injection than adopting the Spring approach? ...