Refactor Axum handlers to inject only the needed services instead of the whole AppData
state
#524
josecelano
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
All the handlers have on their signature an extractor to get the whole AppData state. For example, the handler to get all the categories:
Today, I was discussing with @mario-nt a proposal to make explicit the services needed by a handler in its signature. The previous one would be like this:
This looks cleaner and you know the handler dependencies only by reading its signature. The service calls are also shorter removing the
app_data
prefix. It seems logical to remove the responsibility from the handler to know how to get the service from the app state.The problem is we have to move that responsibility to the router, and it could not be clean. This is how it looks for just one service.
We probably need to add the list of all services used by all handlers at the end (layer). That could be pretty annoying.
Beta Was this translation helpful? Give feedback.
All reactions