How do you ensure a middleware is not applied twice?
My application is using bidi and I have my routes and handlers separate. So my final ring handler has some middlewares (such as wrap-params and wrap-session) and some of my handlers have their own custom middlewares. I can manually watch over my main handler's constructor and my handlers file, but I would rather not rely on manual vigilance.
Is there a design that helps manage middlewares better? Or some library?
My structure looks like this:
1. routes 2. handlers
\ /
\ /
3. (bidi.ring/make-handler routes handlers)
It's possible to wrap something in 2 and then again in 3.
3 is actually a component and make-handler is called in its start. handler & routes come from 3's component's dependencies. I have considered adding another protocol to 1 & 2 with a wrap-middlewares method, but the order of middlewares is significant. For example (buddy-auth's) wrap-authentication depends on wrap-session & wrap-params.