Hi Guice Gurus,

I am just playing with Guice 2.x and I am stuck with an issue that I
can not resolve. Any help would be appreciated.

I have a service class that takes DAO class as a constructor argument
that connects to the data base. The dao class accepts a data source as
a constructor argument. I have created two modules : the first one
injects a JNDI based data source, the other DriverManager based data
source. I would like

public class MyService {

  private final MyDao myDao;


  public MyService(MyDao myDao) {
     this.myDao = myDao;
  }

  ....

}

public class MyDao {
   private final DataSource dataSource;

   @Inject
   public MyDao(DataSource dataSource) {
      this.dataSource = dataSource;
   }

  ....
}

 My modules:

public class JndiDataSourceModule extends AbstractModule {

   public void configure() {
      bind(DataSource.class).toProvider(JndiIntegration.fromJndi
(DataSource.class, "myDatasource"));
   }
}

public class DriverManagerDataSourceModule extends AbstractModule {
   @Provides
    DataSource getDataSource() {
       return DriverManagerDataSource(driverClass, url, username,
password);
    }

   ....
}

I can not figure out how to inject DriverManager based DataSource for
unit tests and JNDI based datasource in my application. I was thinking
of passing modules in the constructor of my service class but I don't
think I would be able to mock my MyDao for exceptional conditions.
Any help would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to google-guice@googlegroups.com
To unsubscribe from this group, send email to 
google-guice+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to