I'm currently building a library right now for other libraries to use. My library uses AspectJ to intercept common function calls and does some modifications. Therefore, other libraries just need to import my package and they're set. In other words, external libraries do not need to instantiate anything from my package.
My package currently uses a Constants
class to keep track of constants, but I wish to use guice to do this for me. Here's an example of what I had in mind:
// pseudoish-code
@Aspect
public class MyAspect {
@Inject
@Named("myConstant")
private static String myConstant;
// currently I'm doing:
// private static String myConstant = Constants.myConstant;
/*
* This method handles intercepting calls to foo(). External libraries using my
* package will have their foo() method intercepted and modified
*/
@Around("execution(* ...foo(..))")
public Object handleFooIntercept(ProceedingJoinpoint jp) {
// do stuff with myConstant
}
}
If I understand guice correctly, I'm going to need to make an injector to actually inject these values:
Injector injector = createInjector(new MyModule()); // binds and provides constants
MyAspect myAspect = injector.getInstance(MyAspect.class);
The problem is that I do not know where to put this. My package does not have an entry point; it simply gets used when other libraries call foo()
. Is my design idea critically flawed? How should I approach this?