Jayashree Madanala
Jayashree Madanala

Reputation: 409

How to skip 2-3 interceptors when there are 5 interceptors for a controller

I have written a controller which invokes service1 method, Before reaching this controller there are 5 interceptors that gets invoked.

No I have new requirement that based on profile or condition, there will be 2 workflows. So I am writing another new service2 that will get invoked in controller based on the condn ex:

Inside controller based on condition i will either service1 method or service2 method.

For service1 method I want all 5 interceptor to be executed and service2 I want only 1-2 interceptor to be executed.

Can you help me how can i acheive this, is it possible to skip few interceptor to be invoked for same controller based on condn

Upvotes: 0

Views: 98

Answers (1)

Igor Bljahhin
Igor Bljahhin

Reputation: 987

There is no way to disable interceptors from app configuration or from some central/uber interceptor.

Technically speaking you can let each interceptor to decide by itself, should it be executed for given request or not, but that's not good solution. This solution means that your business logic is expanded from controller/service layer to the interceptors, but the interceptors should not contain business logic IMHO.

I suggest you to get rid of your 3 interceptors and moved their logic into the controller.

Upvotes: 1

Related Questions