ApplicationState
All the Singleton
types that your application needs to access at runtime
when processing a request are grouped together in a struct called ApplicationState
.
The ApplicationState
is code-generated by Pavex: you don't have to write it yourself!
It is defined in the server SDK crate and exported as a public type.
It is then used in the server crate as an input parameter
to the run
function,
the one that launches the HTTP server to start listening for incoming requests.
Singleton dependencies
Constructors for Singleton
types are invoked before the application starts,
in the generated build_application_state
function.
ApplicationState
is designed to be minimal: it only includes the types that are needed at runtime.
If a Singleton
type is only needed to build another Singleton
type,
it won't be included in the ApplicationState
.
It will be constructed in build_application_state
and then discarded.
If Singleton
type A
is needed to build Singleton
type B
,
you don't have to register a constructor for A
.
Pavex will change the signature of build_application_state
to require A
as input parameter:
you're then free to build A
however you want in the server crate.