feat(container): add singleton lifetime support - #2292
Conversation
|
I'm not sure I'm 100% happy with this approach. It would be more clean if we registered singleton definitions in some kind of config, so that we had a list of attributes available after discovery. That's a pretty large refactor however. The container never used this pattern because it was literally the first component ever to be written for Tempest, before we followed the best practice of discovery writing to config. It's not the end of the world, and I think I'm fine with the current approach, but I'd love some input @innocenzi @xHeaven |
Benchmark ResultsComparison of Open to see the benchmark results
Generated by phpbench against commit 94917bc |
dd86ee6 to
d8f3132
Compare
|
I have several thoughts here...
|
|
I actually think the idea is good, and does align with .NET. "Transient" is just another lifetime, exactly like .NET does. @aidan-casey's second point is valid though, we should be able to specify the lifetime when binding services directly through the We could have this: // generic
$container->bind(..., lifetime: Lifetime::REQUEST);
// shorthands
$container->transient(...);
$container->singleton(...);
$container->perRequest(...); |
No description provided.