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:
You can no longer register a type with a non-'static lifetime parameter (implicit or explicit) as a singleton.
Singletons are no longer forced to be cloned
We validate upfront that all types with a CloneIfNecessary strategy implement Clone
This surfaced a bug where BufferedBody was marked as CloneIfNecessary but didn't implement Clone. This is now fixed.
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 tobuild_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:
CloneIfNecessary
strategy implementClone
BufferedBody
was marked asCloneIfNecessary
but didn't implementClone
. This is now fixed.