Module springtime_di::scope
source · Expand description
Component instances are contained in Scopes - containers which decide when to reuse or create an instance. There’s a global one for singletons, but there also can be other, specialized ones. Some can be simple, like PrototypeScope, while other can be quite complex and depend on external factors, e.g. tying the lifetime of instances to web sessions.
Note: scope resolution happens at component instantiation time, which can lead to unexpected consequences if incompatible scopes are mixed together, e.g. a singleton component can depend on a prototype one. In such case when creating the singleton, a new instance of the dependency will be created, since it’s a prototype, but then that single instance will live as long as the singleton lives.
Structs
- A scope which creates a new instance of a given component on each request. Stateful components usually should be stored in a prototype scope.
- Scope for instances shared between components. Stateless components are good candidates to be stored in the singleton scope.
Constants
- Name of the PrototypeScope.
- Name of the SingletonScope.
Traits
- A scope containing component instances. See module documentation for information on scopes.
- Factory for custom Scopes.