sizovs / PipelinR

PipelinR is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your Java awesome app.
https://github.com/sizovs/PipelinR
MIT License
420 stars 59 forks source link

Middleware After Commands #34

Closed sashokbg closed 11 months ago

sashokbg commented 11 months ago

Hello, I am trying to run something after a command has executed to refresh some caches and things like that. Is it possible to do this with a middleware or a notification handler ?

sizovs commented 11 months ago

Hi @sashokbg

Yes, that's possible and there are many options, including creating a CacheCleaningMiddleware, or AbstractCashCleaningCommand. Same works for notifications. 💡

sashokbg commented 11 months ago

Hello @sizovs I looked again at the examples in the doc and I managed to do it properly. Basically we need to call "next.invoke()" and the put the "after" logic before returning.

  @Override
  public <R, C extends Command<R>> R invoke(C command, Next<R> next) {
      R invoke = next.invoke();
      managerInitService.initPermissions();
      return invoke;
  }