How to introduce app customization with Guice?

23 views
Skip to first unread message

Raffaele Castagno

unread,
Apr 16, 2012, 7:32:33 AM4/16/12
to google...@googlegroups.com
Sorry for the half baked post.

Disclaimer: I'm using a third-party framework, so I don't have control on the 
application startup, I can only do the guice init on-demand inside the services
I create.

Also, I'm new to DI in general and Guice in particular.

I have to introduce a customization mechanism in the app I'm working on.
Basically, I want to be able to do something like this:

public class MyServerClass implements Invokable 
// Invokable is a third-party interface used to tell the server that this class contains services
{
  public static Object myServiceMethod () 
  {
    if(#MyCustomerServiceClass.myServiceMethod# is available)
    {
      return MyCustomerServiceClass.myServiceMethod();
    }
    else
    {
      return MyCoreServiceClass.myServiceMethod();
    }
  }
}

class MyCoreServerClass
{
  public static Object myServiceMethod () 
  {
    return "A";
  }
}

class MyCustomerServiceClass extends MyCoreServerClass
{
  public static Object myServiceMethod () 
  {
    return "B";
  }
}

My requirement is that I should be able to introduce MyCustomerServiceClass without
changing nor recompile MyServerClass MyCoreServerClass.

That is, I have my app with 
MyBasicSetOfClasses.jar
and everything works fine, than I introduce
MyCustomerSpecificClasses.jar
eventually touch some external configuration file, and I have the cusomized myServiceMethod() 
responding to calls to "com.mycompany.MyServerClass.myServiceMethod".

Is it possible to inject dependencies this way, with the new "configuration" inside 
an additional JAR in the classpath or in an external configuration file?

Thanks in advance, and sorry for the double post, and the convoluted and dumb request.

Raffaele C.

Noctarius

unread,
Apr 16, 2012, 1:40:33 PM4/16/12
to google...@googlegroups.com
Hi Raffaele

If you have a chance to build the Guice Injector yourself and
defining which Definitions should be used you can try to intercept
method calls. This could be a possibility.

Cheers Noc

> --
> You received this message because you are subscribed to the Google
> Groups "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/RpSNdNBPcVMJ.
> To post to this group, send email to google...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-guice...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.

Reply all
Reply to author
Forward
0 new messages