Dependency injection #2

Closed
opened 2026-04-25 12:17:03 +02:00 by c.fahner · 1 comment
Owner

Basic dependency injection.

  • Recursive constructor invocation of each dependency
    • Created as "lazy ghosts" to ensure only services that are actually used are instantiated
  • Provide predefined service singletons from the framework
  • Default implementations for service interfaces
    • Avoid a separate bookkeeping that maps service interfaces to instantiable classes
  • Prototypal services that can be further specified using attributes
    • Use case: create a new instance for each invocation
    • Use case: one instance per table name for database table abstractions
  • Restrict access to certain services to specific clients
    • Use case: only allow access to tables from the database abstraction layer
  • Support PHP union and intersection types

Open question: how to deal with "optional dependencies" (technically not a dependency anymore... 😅)? It would be nice to not require a database implementation for running a bare bones instance of the framework that displays information from static files, for example. However, the framework should still be able to provide features such as Origin-header checking or user authentication out of the box - both of which typically require some kind of persistent storage.

Basic dependency injection. * Recursive constructor invocation of each dependency * Created as "lazy ghosts" to ensure only services that are actually used are instantiated * Provide predefined service singletons from the framework * Default implementations for service interfaces * Avoid a separate bookkeeping that maps service interfaces to instantiable classes * Prototypal services that can be further specified using attributes * Use case: create a new instance for each invocation * Use case: one instance per table name for database table abstractions * Restrict access to certain services to specific clients * Use case: only allow access to tables from the database abstraction layer * Support PHP union and intersection types Open question: how to deal with "optional dependencies" (technically not a dependency anymore... 😅)? It would be nice to not require a database implementation for running a bare bones instance of the framework that displays information from static files, for example. However, the framework should still be able to provide features such as Origin-header checking or user authentication out of the box - both of which typically require some kind of persistent storage.
c.fahner added this to the v0.1 milestone 2026-04-25 12:17:03 +02:00
c.fahner added spent time 2026-04-25 20:25:30 +02:00
8 hours
c.fahner stopped working 2026-05-01 15:41:32 +02:00
12 minutes 2 seconds
c.fahner stopped working 2026-05-01 20:33:07 +02:00
2 minutes 46 seconds
Author
Owner

Regarding the "open question":

Currently the framework will simply provide implementations of its own dependencies in an optional module that is packaged with the framework.

If a project wants to override any of the default framework services they can simply provide a custom resolver in the application configs, which will take priority over any #[ImplementedBy] attributes.

Regarding the "open question": Currently the framework will simply provide implementations of its own dependencies in an optional module that is packaged with the framework. If a project wants to override any of the default framework services they can simply provide a custom resolver in the application configs, which will take priority over any `#[ImplementedBy]` attributes.
c.fahner referenced this issue from a commit 2026-05-01 20:41:33 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Total time spent: 8 hours 14 minutes
c.fahner
8 hours 14 minutes
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#1 Request/response flow
slendium/framework
Reference
slendium/framework#2
No description provided.