问题描述
我目前正在建立一个图书馆,供其他图书馆使用。我的库使用AspectJ来拦截常见的函数调用并进行一些修改。因此,其他库只需要导入我的包就可以了。换句话说,外部库不需要实例化我的程序包中的任何内容。
我的程序包当前使用Constants
类来跟踪常量,但是我希望使用guice为我完成此操作。这是我所想到的示例:
// 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
}
}
如果我正确理解guice,则需要制作一个注射器来实际注入这些值:
Injector injector = createInjector(new MyModule()); // binds and provides constants
MyAspect myAspect = injector.getInstance(MyAspect.class);
问题是我不知道该放在哪里。我的包裹没有入口点;它仅在其他库调用foo()
时使用。我的设计理念是否存在严重缺陷?我应该如何处理?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)