Open tp971 opened 8 months ago
I’m not against it, but I cannot think of a situation where I wanted it bottom up. I can see the appeal for it. As a community member I’m not against it, but neither in particular need or desire for it.
Yeah, it'd be good to hear some rationale on this.
The main thing I can think of is that it lets you avoid needing to reference ServiceBuilder
at the callsite of where you're layering... but you're still either importing the helper trait or importing ServiceBuilder
. The resulting layering of the middleware is identical either way.
I am currently working on a project where middleware is applied bottom-up, i.e. the middleware is appended after the services (which is also the case in axum for example, where middlewares are applied after the routes). I noticed that there is no way to add a layer to a service except calling
Layer::layer
or using theServiceBuilder
, both of which are top-down, i.e. the middlewares are added before the services. In my project, I'm currently using this helper trait:This allows you to apply middleware like this:
I see no reason to not include this in
tower::ServiceExt
, so I'm filing this issue as a feature request.