LukeMathWalker / pavex

An easy-to-use Rust framework for building robust and performant APIs
https://pavex.dev
Apache License 2.0
1.67k stars 55 forks source link

feat: Reshape singleton dependencies #298

Closed LukeMathWalker closed 1 month ago

LukeMathWalker commented 1 month ago

This is a fairly big change to Pavex's dependency injection system. Before this PR, all singleton dependencies were automatically added as inputs to build_application_state if they had no registered constructor. There was no way to explicitly tell Pavex, "Please, add this as input to build_application_state, I'll build it for you".

After this PR, singleton dependencies are no longer special-cased. If there's no constructor for them, you'll get an error. But you now have two options for resolving it: register a constructor or mark them as "prebuilt types."
Prebuilt types (if used) will be added as inputs to build_application_state and then used as if they had been built by Pavex. The same logic applies to constructed types, e.g. cloning strategy.

This brings along a few other changes:

LukeMathWalker commented 1 month ago

/ok-to-test sha=3da8391

LukeMathWalker commented 1 month ago

/ok-to-test sha=106d2bd

LukeMathWalker commented 1 month ago

/ok-to-test sha=d3f661f

LukeMathWalker commented 1 month ago

/ok-to-test sha=e871432