A interesting question was raised in #2256 on how the container should resolve dependencies.
First, we should discuss the current situation: Tempest's container defaults to non-singletons. Whenever you ->get() a dependency from the container, it will create a new one, unless there's an explicit singleton definition for it (defined either with $container->singleton, an initializer with #[Singleton], or a class tagged with #[Singleton]).
Now there are three questions to discuss:
- Can we design an API that makes it trivial for users to explicitly retrieve non-singleton objects, even though they have a singleton definition?
- Can we make it so the container's default resolution strategy can be changed?
- What should the default resolution strategy be?
Let's discuss
A interesting question was raised in #2256 on how the container should resolve dependencies.
First, we should discuss the current situation: Tempest's container defaults to non-singletons. Whenever you
->get()a dependency from the container, it will create a new one, unless there's an explicit singleton definition for it (defined either with$container->singleton, an initializer with#[Singleton], or a class tagged with#[Singleton]).Now there are three questions to discuss:
Let's discuss