google / google/guice

Can I have more than one aspect for a method and if yes how to ensure order of them with Guice AOP

Open
#1,659 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

I have single method say "updateTransaction". Now I have two aspects , logging and authorization on this method.

Authorization aspect checks whether logged in user is authorized to update the transaction and logging aspect logs the parameters.
I can

Module Code:

```
AuthorizationImpl authorization = new AuthorizationImpl();
this.requestInjection(authorization);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(Authorized.class), authorization);

final Logger logger= new Logger();
this.requestInjection(logger);
this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Logger.class), logger);
```

Method :

```
@Authorized
@Logger
public boolean updateTransaction(...)
```
Questions:
1. It should invoke updateTransaction method only once, even though I have two interceptors, both are calling invocation.proceed
2. If the authorization aspect does not allow updateTransaction to be called, then even logger aspect should not call it via proceed.
3. How to ensure the order of those two aspects ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.