Make AppContext
extensible via traits
#777
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #522
This PR changes the
Hooks
trait to be generic over theAppContextTrait
allowing end users to provide their own structs for application context. This allows for greater flexibility of end users to define the context of their web server as well as makes accessing user defined global application state smoother in various parts of the loco framework.This change is implemented via two traits. The first being the object-safe
Context
trait and the second being the fullAppContextTrait
. The reason behind the split is that tasks and initializers are required to be object-safe and to pass in a generic type, that trait also needs to be object-safe. There are other places where the generic type is required to beClone
and/orDefault
making it impossible to implement in one trait. So where object-safety is required theContext
trait is used and everywhere elseAppContextTrait
is used.Splitting the implementation into the
Context
trait andAppContextTrait
also allows for the definition of acreate
method so the internals of the framework can construct the generic type with minimal disruption to the current code.