7

I don't quite understand what the @with annotation does.

in the Play framework site, it is written :

we can annotate the controllers using the @With annotation to tell Play to invoke the corresponding interceptors

is it the same as inheritance ? will it invoke @before of the given class parameter ? what exactly does it do ?

0

2 Answers 2

7

The best way I can describe it, is that it kind of gives you multiple inheritance at your controller level for your interceptors. Interceptors being the @Before, @After annotations.

You could therefore

  • define a controller that dealt with your secure area @Before annotations
  • define a controller that dealt with injecting your static data for shared actions using @Before

you could then define a controller or controllers that contained all your actions, and use the @With annotation to make use of the two controllers described above. It means you can separate your code out cleanly, and not have to rely on inheritance to execute the @Before annotations.

Sign up to request clarification or add additional context in comments.

Comments

6

Suppose you have 2 controllers:

  • A has @Before or other controller action injection annotations,
  • B get annotated with @With(A.class)

All those injection actions defined in A will be effective when calling B's action methods.

It's kind of inheritance. However with inheritance you can extend at most one class. But you can do @With({A.class, Z.class, ...})

2 Comments

If i understand you correctly, in B class i can call any method that is in A class (implicitly) ?
No, just intercepters ((at)Before, (at)After, (at)Final etc) will work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.