Search Results

Search found 94 results on 4 pages for 'guice'.

Page 1/4 | 1 2 3 4  | Next Page >

  • Proper structure for dependency injection (using Guice)

    - by David B.
    I would like some suggestions and feedback on the best way to structure dependency injection for a system with the structure described below. I'm using Guice and thus would prefer solutions centered around it's annotation-based declarations, not XML-heavy Spring-style configuration. Consider a set of similar objects, Ball, Box, and Tube, each dependent on a Logger, supplied via the constructor. (This might not be important, but all four classes happen to be singletons --- of the application, not Gang-of-Four, variety.) A ToyChest class is responsible for creating and managing the three shape objects. ToyChest itself is not dependent on Logger, aside from creating the shape objects which are. The ToyChest class is instantiated as an application singleton in a Main class. I'm confused about the best way to construct the shapes in ToyChest. I either (1) need access to a Guice Injector instance already attached to a Module binding Logger to an implementation or (2) need to create a new Injector attached to the right Module. (1) is accomplished by adding an @Inject Injector injectorfield to ToyChest, but this feels weird because ToyChest doesn't actually have any direct dependencies --- only those of the children it instantiates. For (2), I'm not sure how to pass in the appropriate Module. Am I on the right track? Is there a better way to structure this? The answers to this question mention passing in a Provider instead of using the Injector directly, but I'm not sure how that is supposed to work. EDIT: Perhaps a more simple question is: when using Guice, where is the proper place to construct the shapes objects? ToyChest will do some configuration with them, but I suppose they could be constructed elsewhere. ToyChest (as the container managing them), and not Main, just seems to me like the appropriate place to construct them.

    Read the article

  • How to integrate Guice 2 into Wicket?

    - by deamon
    I want to use Guice 2 with Wicket 1.4. There is a "wicket-guice" package, which uses Guice 1. Can someone give me an example how to configure Wicket to use Guice 2 for injection (with Maven). As you can see blow, I've found a solution, but I wonder, if it would be better to use Guice Servlets and register the whole Wicket Application as a ServletFilter with Guice. But I think this would conflict with wickets object creation strategy.

    Read the article

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

    - by sme
    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 excluded from the obfuscation. The stack trace looks like this: com.google.inject.CreationException: Guice creation errors: 1) Cannot inject a Provider that has no type parameter while locating com.google.inject.Provider for parameter 0 at de.repower.lvs.client.admin.user.administration.AdminUserCommonPanel.setPasswordPanelProvider(SourceFile:499) at de.repower.lvs.client.admin.user.administration.AdminUserCommonPanel.setPasswordPanelProvider(SourceFile:499) while locating de.repower.lvs.client.admin.user.administration.AdminUserCommonPanel for parameter 0 at de.repower.lvs.client.admin.user.administration.b.k.setParentPanel(SourceFile:65) at de.repower.lvs.client.admin.user.administration.b.k.setParentPanel(SourceFile:65) at de.repower.lvs.client.admin.user.administration.o.a(SourceFile:38) 2) Cannot inject a Provider that has no type parameter while locating com.google.inject.Provider for parameter 0 at de.repower.lvs.client.admin.user.administration.AdminUserCommonPanel.setWindTurbineAccessGroupProvider(SourceFile:509) at de.repower.lvs.client.admin.user.administration.AdminUserCommonPanel.setWindTurbineAccessGroupProvider(SourceFile:509) while locating de.repower.lvs.client.admin.user.administration.AdminUserCommonPanel for parameter 0 at de.repower.lvs.client.admin.user.administration.b.k.setParentPanel(SourceFile:65) at de.repower.lvs.client.admin.user.administration.b.k.setParentPanel(SourceFile:65) at de.repower.lvs.client.admin.user.administration.o.a(SourceFile:38) 2 errors at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) at com.google.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:152) at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:105) at com.google.inject.Guice.createInjector(Guice.java:92) at com.google.inject.Guice.createInjector(Guice.java:69) at com.google.inject.Guice.createInjector(Guice.java:59) I tried to create a small example (without using guice) that seems to reproduce the problem: package de.repower.common; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; class SomeClass<S> { } public class ParameterizedTypeTest { public void someMethod(SomeClass<Integer> param) { System.out.println("value: " + param); System.setProperty("my.dummmy.property", "hallo"); } private static void checkParameterizedMethod(ParameterizedTypeTest testObject) { System.out.println("checking parameterized method ..."); Method[] methods = testObject.getClass().getMethods(); for (Method method : methods) { if (method.getName().equals("someMethod")) { System.out.println("Found method " + method.getName()); Type[] types = method.getGenericParameterTypes(); Type parameterType = types[0]; if (parameterType instanceof ParameterizedType) { Type parameterizedType = ((ParameterizedType) parameterType).getActualTypeArguments()[0]; System.out.println("Parameter: " + parameterizedType); System.out.println("Class: " + ((Class) parameterizedType).getName()); } else { System.out.println("Failed: type ist not instance of ParameterizedType"); } } } } public static void main(String[] args) { System.out.println("Starting ..."); try { ParameterizedTypeTest someInstance = new ParameterizedTypeTest(); checkParameterizedMethod(someInstance); } catch (SecurityException e) { e.printStackTrace(); } } } If you run this code unsbfuscated, the output looks like this: Starting ... checking parameterized method ... Found method someMethod Parameter: class java.lang.Integer Class: java.lang.Integer But running the version obfuscated with proguard yields: Starting ... checking parameterized method ... Found method someMethod Failed: type ist not instance of ParameterizedType These are the options I used for obfuscation: -injars classes_eclipse\methodTest.jar -outjars classes_eclipse\methodTestObfuscated.jar -libraryjars 'C:\Program Files\Java\jre6\lib\rt.jar' -dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclassmembers -dontshrink -printusage classes_eclipse\shrink.txt -dontoptimize -dontpreverify -verbose -keep class **.ParameterizedTypeTest.class { <fields>; <methods>; } -keep class ** { <fields>; <methods>; } # Keep - Applications. Keep all application classes, along with their 'main' # methods. -keepclasseswithmembers public class * { public static void main(java.lang.String[]); } # Also keep - Enumerations. Keep the special static methods that are required in # enumeration classes. -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } # Also keep - Database drivers. Keep all implementations of java.sql.Driver. -keep class * extends java.sql.Driver # Also keep - Swing UI L&F. Keep all extensions of javax.swing.plaf.ComponentUI, # along with the special 'createUI' method. -keep class * extends javax.swing.plaf.ComponentUI { public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent); } # Keep names - Native method names. Keep all native class/method names. -keepclasseswithmembers,allowshrinking class * { native <methods>; } # Keep names - _class method names. Keep all .class method names. This may be # useful for libraries that will be obfuscated again with different obfuscators. -keepclassmembers,allowshrinking class * { java.lang.Class class$(java.lang.String); java.lang.Class class$(java.lang.String,boolean); } Does anyone have an idea of how to solve this (apart from the obvious workaround to put the relevant files into a seperate jar and not obfuscate it)? Best regards, Stefan

    Read the article

  • Injecting generics with Guice

    - by paradigmatic
    I am trying to migrate a small project, replacing some factories with Guice (it is my first Guice trial). However, I am stuck when trying to inject generics. I managed to extract a small toy example with two classes and a module: import com.google.inject.Inject; public class Console<T> { private final StringOutput<T> out; @Inject public Console(StringOutput<T> out) { this.out = out; } public void print(T t) { System.out.println(out.converter(t)); } } public class StringOutput<T> { public String converter(T t) { return t.toString(); } } import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.TypeLiteral; public class MyModule extends AbstractModule { @Override protected void configure() { bind(StringOutput.class); bind(Console.class); } public static void main(String[] args) { Injector injector = Guice.createInjector( new MyModule() ); StringOutput<Integer> out = injector.getInstance(StringOutput.class); System.out.println( out.converter(12) ); Console<Double> cons = injector.getInstance(Console.class); cons.print(123.0); } } When I run this example, all I got is: Exception in thread "main" com.google.inject.CreationException: Guice creation errors: 1) playground.StringOutput<T> cannot be used as a key; It is not fully specified. at playground.MyModule.configure(MyModule.java:15) 1 error at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) at com.google.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:152) at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:105) at com.google.inject.Guice.createInjector(Guice.java:92) I tried looking for the error message, but without finding any useful hints. Further on the Guice FAQ I stumble upon a question about how to inject generics. I tried to add the following binding in the configure method: bind(new TypeLiteral<StringOutput<Double>>() {}).toInstance(new StringOutput<Double>()); But without success (same error message). Can someone explain me the error message and provide me some tips ? Thanks.

    Read the article

  • Build path issues learning Guice

    - by Preston
    I can't figure out why I'm getting this error below I have included all the appropriate jars as far as I can tell(I have included eclipses .classpath file below.) All of the classpath entries resolve just fine. What am I missing? The type javax.servlet.ServletContextListener cannot be resolved. It is indirectly referenced from required .class files on the "extends GuiceServletContextListener" line - import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.servlet.GuiceServletContextListener; import com.google.inject.servlet.ServletModule; public class ServletConfig extends GuiceServletContextListener { @Override protected Injector getInjector() { return Guice.createInjector(new ServletModule(){ @Override protected void configureServlets() { // TODO: add necessary code to bind } }); } } .Classpath <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_21"> <attributes> <attribute name="owner.project.facets" value="java"/> </attributes> </classpathentry> <classpathentry kind="con" path="oracle.eclipse.tools.glassfish.lib.system"> <attributes> <attribute name="owner.project.facets" value="jst.web"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="lib" path="guice-3.0/aopalliance.jar"/> <classpathentry kind="lib" path="guice-3.0/guice-3.0.jar"/> <classpathentry kind="lib" path="guice-3.0/guice-servlet-3.0.jar"/> <classpathentry kind="lib" path="guice-3.0/javax.inject.jar"/> <classpathentry kind="output" path="build/classes"/> </classpath>

    Read the article

  • How do I bind Different Interfaces using Google Guice?

    - by kunjaan
    Do I need to create a new module with the Interface bound to a different implementation? Chef newChef = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl.class); } }).getInstance(Chef.class); Chef newChef2 = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl2.class); } }).getInstance(Chef.class); I cannot touch the Chef Class nor the Interfaces. I am just a client binding to Chef's FortuneService to different Interfaces at runtime.

    Read the article

  • Hidden Features of Google Guice

    - by Jon
    Google Guice provides some great dependency injection features. I came across the @Nullable feature recently which allows you to mark constructor arguments as optional (permitting null) since Guice does not permit these by default: e.g. public Person(String firstName, String lastName, @Nullable Phone phone) { this.firstName = checkNotNull(firstName, "firstName"); this.lastName = checkNotNull(lastName, "lastName"); this.phone = phone; } http://code.google.com/p/google-guice/wiki/UseNullable What are the other useful features of Guice (particularly the less obvious ones) that people use?

    Read the article

  • How to test Guice Singleton?

    - by 01
    Guice Singletons are weird for me First I thought that IService ser = Guice.createInjector().getInstance(IService.class); System.out.println("ser=" + ser); ser = Guice.createInjector().getInstance(IService.class); System.out.println("ser=" + ser); will work as singleton, but it returns ser=Service2@1975b59 ser=Service2@1f934ad its ok, it doesnt have to be easy. Injector injector = Guice.createInjector(); IService ser = injector.getInstance(IService.class); System.out.println("ser=" + ser); ser = injector.getInstance(IService.class); System.out.println("ser=" + ser); works as singleton ser=Service2@1975b59 ser=Service2@1975b59 So i need to have static field with Injector(Singleton for Singletons) how do i pass to it Module for testing?

    Read the article

  • Guice and JSF 2

    - by digitaljoel
    I'm trying to use Guice to inject properties of a JSF managed bean. This is all running on Google App Engine (which may or may not be important) I've followed the instructions here: http://code.google.com/docreader/#p=google-guice&s=google-guice&t=GoogleAppEngine One problem is in the first step. I can't subclass the Servlet module and setup my servlet mappings there because Faces is handled by the javax.faces.webapp.FacesServlet which subclasses Servlet, not HttpServlet. So, I tried leaving my servlet configuration in the web.xml file and simply instantiating a new ServletModel() along with my business module when creating the injector in the context listener described in the second step. Having done all that, along with the web.xml configuration, my managed bean isn't getting any properties injected. The method is as follows @ManagedBean @ViewScoped public class ViewTables implements Serializable { private DataService<Table> service; @Inject public void setService( DataService<Table> service ) { this.service = service; } public List<Table> getTables() { return service.getAll(); } } So, I'm wondering if there is a trick to get Guice injecting into a JSF managed bean? I obviously can't use the constructor injection because JSF needs a no-arg constructor to create the bean.

    Read the article

  • How to use Guice in Swing application

    - by Gerco Dries
    I have a Swing application that I would like to convert from spaghetti to using dependency injection with Guice. Using Guice to provide services like configuration and task queues is going great but I'm now starting on the GUI of the app and am unsure of how to proceed. The application is basically a JFrame with a bunch of tabs in a JTabbedPane. Each of the tabs is a separate JPanel subclass that lays out the various components and needs services to perform actions when certain buttons are pressed. In the current application, this looks somewhat like this: @Inject public MainFrame(SomeService service, Executor ex, Configuration config) { tabsPane = new JTabbedPane(); // Create the panels for each tab and add them to the tabbedpane somePanel = new SomeTabPanel(service, ex, config); tabsPane.addTab("Panel 1", somePanel); someOtherPanel = new SomeOtherTabPanel(service, ex, config); tabsPane.addTab("Panel 2", someOtherPanel); ... do more stuff } Obviously, this doesn't exactly follow DI best practices. I don't want to have to @Inject the tabs because that would get me a constructor with dozens of parameters. I do want to use Guice to inject the required dependencies into whatever tab objects I need without me having to pass all of those dependencies to the tab constructors. All of the dependencies for the tab objects are services that my Module knows about, so basically all I think I want to do is to ask Guice for the required objects and have them constructed for me.

    Read the article

  • What problem does Peaberry for Guice solve?

    - by Benju
    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 presentations. http://code.google.com/p/peaberry/

    Read the article

  • Using Guice with circular dependencies

    - by Yury Litvinov
    Consider this simple example. Class A { B b; A() { this.b = new B(this); } } In this example instance A knows about instance B, and instance B knows about instance A. My question is: how to instantiate instance A with Guice, i.e. how to make Guice take care of this complex circle dependencies?

    Read the article

  • How do I create different Objects using Google Guice?

    - by kunjaan
    I have a Module which binds an Interface to a particular implementation. I use that module to create an object. How do I create a different kind of object with the the interface bound to a different implementation? Do I need to create a new module with the Interface bound to a different implementation?

    Read the article

  • Guice + Quartz + iBatis

    - by DroidIn.net
    I'm trying to wire together Guice (Java), Quartz scheduler and iBatis (iBaGuice) to do the following: Start command line utility-scanner using main() Periodically scan directory (provided as argument) for files containing formatted output (XML or YAML) When file is detected, parse and output result to the database The problems: I used this example to wire Guice and Quartz. However I'm missing some important details which I'm asking in the comments but the post is somewhat dated so I'm quoting it here also: It's not obvious how to set-up the scheduler. Where and how would I wire the Trigger (I can use Trigger#makeMinutelyTrigger)? I really have just one type of job I will be executing, I understand that details in the JobFactory#newJob are coming from the TriggerFiredBundle parameter but where/how do I wire that? And where/how do I create or wire concrete Job?

    Read the article

  • Dependency injection: Scoping by region (Guice, Spring, Whatever)

    - by Itay
    Here's a simplified version of my needs. I have a program where every B object has its own C and D object, injected through Guice. In addition an A object is injected into every C and D objects. What I want: that for each B object, its C and D objects will be injected with the same A object. Specifically, I want the output of the program (below) to be: Created C0 with [A0] Created D0 with [A0] Created B0 with [C0, D0] Created C1 with [A1] Created D1 with [A1] Created B1 with [C1, D1] Where it currently produces the following output: Created C0 with [A0] Created D0 with [A1] <-- Should be A0 Created B0 with [C0, D0] Created C1 with [A2] <-- Should be A1 Created D1 with [A3] <-- Should be A1 Created B1 with [C1, D1] I am expecting DI containers to allow this kind of customization but so far I had no luck in finding a solution. Below is my Guice-based code, but a Spring-based (or other DI containers-based) solution is welcome. import java.util.Arrays; import com.google.inject.*; public class Main { public static class Super { private static Map<Class<?>,Integer> map = new HashMap<Class<?>,Integer>(); private Integer value; public Super(Object... args) { value = map.get(getClass()); value = value == null ? 0 : ++value; map.put(getClass(), value); if(args.length > 0) System.out.println("Created " + this + " with " + Arrays.toString(args)); } @Override public final String toString() { return "" + getClass().getSimpleName().charAt(0) + value; } } public interface A { } public static class AImpl extends Super implements A { } public interface B { } public static class BImpl extends Super implements B { @Inject public BImpl(C c, D d) { super(c,d); } } public interface C { } public static class CImpl extends Super implements C { @Inject public CImpl(A a) { super(a); } } public interface D { } public static class DImpl extends Super implements D { @Inject public DImpl(A a) { super(a); } } public static class MyModule extends AbstractModule { @Override protected void configure() { bind(A.class).to(AImpl.class); bind(B.class).to(BImpl.class); bind(C.class).to(CImpl.class); bind(D.class).to(DImpl.class); } } public static void main(String[] args) { Injector inj = Guice.createInjector(new MyModule()); inj.getInstance(B.class); inj.getInstance(B.class); } }

    Read the article

  • Guice expert question

    - by Roman
    Hi All I am wondering if someone would be such an expert in guice that he even would know how to implement that : I have an injection annotation (@ConfParam)with some parameters , like that : class TestClass { private final int intValue; @Inject public TestClass(@ConfParam(section = "test1", key = "1") int intValue{ this.intValue = intValue; } public int getIntValue() { return intValue; } } The ConfParam is my custom annotation. Now , when the injection value is requested , I would like guice to create a dynamic binding, to resolve the value. For that binding I will need the parameters inside the annotation. Some example could be , I will have to look in the database in some table where the section is ? and the key is ?. All the trouble is that the data is not available when the injector is created and could be also be added at runtime. Ps. I static solution is easy. ( just have a look at the Names class)

    Read the article

  • Auto injecting logger with guice

    - by koss
    With reference to Guice's custom injections article, its TypeListener performs a check for InjectLogger.class annotation - which can be optional. Removing that check will inject to all Logger.class types. class Log4JTypeListener implements TypeListener { public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) { for (Field field : typeLiteral.getRawType().getDeclaredFields()) { if (field.getType() == Logger.class && field.isAnnotationPresent(InjectLogger.class)) { typeEncounter.register(new Log4JMembersInjector<T>(field)); } } } } I'm tempted to remove "&& field.isAnnotationPresent(InjectLogger.class)" from the listener. If we're using Guice to inject all instances of our Logger, is there any reason not to do it automatically (without need to annotate)?

    Read the article

  • Using NetBeans profiler with Guice classes

    - by Karussell
    How can I use the profiler from NetBeans 6.8 or 6.9 (choosing 'entire application') with guice enhanced classes? I am using google guice 2.0 (with warp persist 2.0-20090214) for some classes and wanted to profile those classes. But I cannot see a result for those classes. The only result I can see is for one method 'EnhancedClass.access$000' which is not very helpful. Other classes are working. Does somebody know a workaround? Or know what I am doing wrong?

    Read the article

  • Guice child injector override binding

    - by Roman
    Hi All I am trying to to override a binding in a child injector that was already configured in a base injector. like that : public class PersistenceModule extends Abstract{ @Override protected void configure() { bind(IProductPersistenceHelper.class).to(ProductPersistenceHelper.class); } } then : Injector injector = Guice.createInjector(new PersistenceModule()); injector.createChildInjector(new AbstractModule(){ @Override protected void configure() { bind(IProductPersistenceHelper.class).to(MockProductPersistenceHelper.class); } }) Guice is complaining that it has already a binding for that. Are there any patterns or best practices for that problem ?

    Read the article

  • Guice, JDBC and managing database connections

    - by pledge
    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 numerous repositories which reuse the same connection and participate in the same transaction. My questions are: Where do I create my Datasource? How do I give the repositories access to the connection? (ThreadLocal?) Best way to manage the transaction (Creating an Interceptor for an annotation?) The code below shows how I would do this in Spring. The JdbcOperations injected into each repository would have access to the connection associated with the active transaction. I haven't been able to find many tutorials which cover this, beyond ones which show creating interceptors for transactions. I am happy with continuing to use Spring as it is working very well in my projects, but I'd like to know how to do this in pure Guice and JBBC (No JPA/Hibernate/Warp/Reusing Spring) @Service public class MyService implements MyInterface { @Autowired private RepositoryA repositoryA; @Autowired private RepositoryB repositoryB; @Autowired private RepositoryC repositoryC; @Override @Transactional public void doSomeWork() { this.repositoryA.someInsert(); this.repositoryB.someUpdate(); this.repositoryC.someSelect(); } } @Repository public class MyRepositoryA implements RepositoryA { @Autowired private JdbcOperations jdbcOperations; @Override public void someInsert() { //use jdbcOperations to perform an insert } } @Repository public class MyRepositoryB implements RepositoryB { @Autowired private JdbcOperations jdbcOperations; @Override public void someUpdate() { //use jdbcOperations to perform an update } } @Repository public class MyRepositoryC implements RepositoryC { @Autowired private JdbcOperations jdbcOperations; @Override public String someSelect() { //use jdbcOperations to perform a select and use a RowMapper to produce results return "select result"; } }

    Read the article

  • How test guice injections?

    - by yeraycaballero
    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 } } Notice A hasn't got a getB() method and I want to assert that A.b isn't null.

    Read the article

  • Hierarchy of modules in guice

    - by Niko
    Hi, I'd like to run a unit test where a constant is slightly different than in the standard version. That is, in my default module, the following is bindConstant().annotatedWith(Names.named("number of players")).to(4); but in testing, I'd like to try this line instead: bindConstant().annotatedWith(Names.named("number of players")).to(2); Id like to achieve that without copying all of the rest of the module. What I really want is a "default" module that is "below" a more specialized module, such that in case of conflict, the specialized module wins (instead of throwing an exception, which is what guice does). In essence, my question is: how does anybody arrange for more than one module without lots of code duplication?

    Read the article

  • Guice ThrowingProvider problem

    - by KARASZI István
    According to the ThrowingProvider documentation of Guice I have the following interface: public interface IConfigurableProvider<T> extends ThrowingProvider<T, ConfigException> {} I have multiple classes that implements this interface, let assume I have the following: public class SomethingProvider extends ConfiguredProvider implements IConfigurableProvider<Something> {} Of course this class implements the necessary method: public Something get() throws ConfigException { /* ... */ } In my module, I have the following code in MyModule.java ThrowingProviderBinder.create(binder()) .bind(IConfigurableProvider.class, Something.class) .to(SomethingProvider.class); But when I start my application the following error produced: 6) No implementation for com.package.Something was bound. while locating com.package.Something for parameter 5 at com.package.OtherClass.<init>(OtherClass.java:78) at com.package.MyModule.configure(MyModule.java:106) I don't really know where should I start looking for the bug.

    Read the article

  • Guice Problem with Tests

    - by D3orn
    Hey I wrote a LudoGame and now I like to test it with a little GuiceInjection^^ I have an Interface IDie for my die. Now for the game I only need an IDie instead of a realdie = in tests I simply give the LudoGame a MokeDie to set up the Numbers I like to roll. The IDie has only one method: roll() which returns a int. BUT the mokeDie now has another public method: sendNextNumber() (should be clear what this does^^) Now I like to @Inject a Die and if @UseMokeDie is before a Test I'll like to pass the MokeDie but I'm very new to Guice... Need some advices please! Thx for Answers

    Read the article

1 2 3 4  | Next Page >