how to Inject the module dynamically like if version == "1.1" then inject 1.1 module else inject 1.0 module

61 views
Skip to first unread message

Amit Sonkar

unread,
Sep 28, 2015, 1:29:57 AM9/28/15
to google-guice
I am working on a struts2 project in which guice is used for dependency injection. Now i have a java project in which services are written for 1.0 version and 1.1 version like below.

public interface Services
{
   public void meth1();
}

public class ServiceImpl1_0 implements Services
{
   public void meth1()
   {
   }
}

public class ServiceImpl1_1 implements Services
{
   public void meth1()
   {
   }
}

I created two guice modules, one to inject 1_0 version and another to inject 1_1 version.

This project is consumed in main project where i have to inject the dependency based on the version number like 

if version 1.0 then install 1_0 guice module else install 1_1 guice module.

Please help me how can i achieve it?

Stephan Classen

unread,
Sep 29, 2015, 6:22:19 PM9/29/15
to google...@googlegroups.com
You could make a third module which checks the version and then delegates all method calls to the either 1.0 or 1.1
Reply all
Reply to author
Forward
0 new messages