Skip to content

Choosing an Implementation

How you construct your container is up to you, but you should decide up front whether you want to compile the dependency graph or not. All three implementations produce a container with the exact same runtime API — they differ only in how the container is assembled.

DefaultDynamicCustom Build
How services are defined.ctn container filesPHP bind() calls at runtimeAny source (JSON, array, …) fed to the builder
Compiled to a PHP class✅ Yes❌ No✅ Yes
Runtime speedFastestSlowerFastest
Needs a writable cache dir
Flexibility at runtimeAdd/override via bind()UnlimitedAdd/override via bind()
Best forMost applicationsTests, tiny scripts, fully dynamic graphsYou want compilation but not the .ctn language

Recommendation

  • Use the Default implementation for real applications — declare your services in .ctn files and let them compile.
  • Use the Dynamic container for tests, throwaway scripts, or when the service graph is only known at runtime.
  • Use a Custom Build when you want the compilation benefit but prefer to describe services in your own format instead of .ctn files.

You can always mix in runtime service binding on top of a compiled container.

See The Container Lifecycle for what "compiling" actually does.