Guess: The new Guice Aop Api
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
Hi all: I think the current apiice aop api is somewhat complicated and difficult to use.
I have a simplified idea:
* For non-ioc containers:
```
T proxy = GuiceAop.proxy(Class)
.byInstance(instance)
.around(proxyContext -> {
String name = proxyContext.getInfo().getName();
System.out.println(name);
Object value = proxyContext.proceed();
//..after
});
```
* Rely on Ioc containers:
```
Injector injector = Guice.create(binder -> {
binder.bind(Map.class).byCreator(HashMap::new).withSingle();
binder.bind(HashSet.class).by(HashSet.class).withSingle();
}).aop(binder -> {
binder.bind("point1")
.withPackage("com.github.harbby")
//.subclassOf(Map.class)
.classAnnotated()
.classes(HashMap.class, HashSet.class)
.whereMethod(methodInfo -> methodInfo.getName().startsWith("add"))
.build()
.before((info) -> {
Assert.assertEquals("add", info.getName());
System.out.println("before1");
})
.after(() -> {
Assert.assertTrue(true);
System.out.println("after2");
});
}).initialize();
Set set = injector.getInstance(HashSet.class);
```
Contributor guide
Assessment
This issue has not been assessed yet.