Skip to content

Instantly share code, notes, and snippets.

@cspray
Last active August 6, 2022 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cspray/0a9d4294af4da5221d1ab174ad074bd1 to your computer and use it in GitHub Desktop.
Save cspray/0a9d4294af4da5221d1ab174ad074bd1 to your computer and use it in GitHub Desktop.
Amp Injector Overview

Amp Injector Overview

This document details the high-level technical workings of the amphp/injector project. Specifically, this document has 2 primary goals:

  1. Serve as a basis for more thorough documentation in the amphp/injecto repo proper.
  2. Serve as a technical guide for integrating with cspray/annotated-container.

How it Works

Amphp Injector is split into a set of systems to define and construct your container. Composing these systems together allows you to wire an object graph with the following functionalities:

  • Shared services
  • Recursively autowiring service dependencies
  • Specify injection parameters for constructor and method calls
  • Specify a factory to be used for creating a service
  • Preparing a service after construction
  • ?????????

Injector Technical Details

A Provider describes how to create a service or non-object value to be stored in the Container. A Provider also allows you to define any other Providers that might be depended upon. For example, a ServiceProvider could declare a dependency on DatabaseProvider to ensure a database connection service is available.

A Definition is... TBD

A Weaver defines how to determine arguments to use for a constructor or method call (?). Implementations allow recursively autowiring parameters, to define a parameter that should be pulled from the Container, or the direct value of the parameter.

Open Questions

  1. How precisely do Definition and Definitions fit into the Provider and Weaver?
  2. What is an "attribute" on a Definition?
  3. How to alias a service?
  4. How to define a factory for a service?
  5. How to prepare a service after construction?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment