In my applications I need to be able to have some influence on how Guice 
searches for bindings.

The problem that I am trying to solve:
I have a system to generate alerts. The code that generates these alerts 
need to declare an interface that extends a marker interface and all the 
methods use annotations to declare the actual text with placeholders for 
the parameters. The actual implementation of this interface is done by one 
single dynamic proxy implementation. For example

public interface Alerts {}

public interface TestAlerts extends Alerts {
  @Alert( "Hello {0}" )
  public void hello( String text );
}

In the application code I inject the TestAlerts and use it like a regular 
object. The advantage of this approach is that I get nice compiler warnings 
whenever a change to parameters is done, or a message has been removed from 
the Alerts interface. I can also do decent formatting and type conversion 
without complicating the code that uses my Alert system.

Right now I have 2 possibilities in Guice:
1) bind all interfaces that extends Alerts with a provider that can create 
the dynamic proxy specific to the requested interface.
2) Inject an AlertFactory that has a <V extends Alerts> V create(Class<V> 
typeClass ) method.

Solution 1 becomes tedious because in my case we are talking about hundreds 
of injections (large enterprise system with lots of independent components).
Solution 2 exposes the fact that you need to use a factory to send a simple 
alert. Somehow this feels a bit like an anti-pattern because I am not 
interested in how to create these objects, I just want on instance by magic 
as I am used in injection frameworks.

I've read and tried the documentation section on custom Custom Injections 
<https://github.com/google/guice/wiki/CustomInjections>. But is very 
incomplete, since it only allows injection into members, not constructors 
and it requires you to use a custom annotation, not @Inject which basically 
already requires the class to know that what he is depending on needs some 
kind of extension - which sounds like an anti-pattern to me.

I would like to be able to somehow register that Guice should use a Factory 
that takes an argument of type class<V extends Alerts>. Or someway to 
register a TypeListener that gets invoked when some unknown type is 
requested for injection. 

Any ideas how to do this ? Any chance of getting some extra extension point 
in Guice to go a step further with extensions ?


-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/d3e36ad3-c49b-4cbb-9640-6527877491bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to