Separate handler state types #1739
Unanswered
danielgrigg
asked this question in
Q&A
Replies: 1 comment
-
You're probably missing If you really do want different states you can do this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, new axum user and loving it! I had a question on how to approach architecting routes and stateful dependencies.
I'm trying to create some routes such that each handler injects only its required dependencies, eg a create_user handler might only inject a UserRepository but the whole app may consist of a hundred such repositories and bundling them all into a shared state isn't ideal.
I saw there's a with_state method and the docs and example suggest that independent handlers with differing state types can be merged together but I don't see it'd compile given the type constraint that the (using example types) InnerState be convertible into the OuterState? Am I trying to use it correctly? Or should I use another method?
For now I'm using a single state type but I can quickly see it becoming a god class coupled to everything.
Beta Was this translation helpful? Give feedback.
All reactions