No DI Container in Laravel Go — Yet Laravel Rust Has One: Comparing Dependency Injection Across PHP, Go, and Rust
For fifteen years, the Service Container has been the beating heart of Laravel PHP. Type-hint a class in a controller constructor or route method, and Laravel resolves the entire dependency graph via reflection automatically.
So when developers started exploring Laravel Go (go.laravel.com v0.2.0), one architectural decision immediately sparked debate: Laravel Go has no DI container.
Even more surprising: open Laravel Rust (laravel-rust 0.2.0), built by the exact same organization in the exact same week, and you will find a full Service Container with singleton, bind, dyn Trait contracts, #[singleton] attributes, and typed Inject<T> handler extractors.
Why did the Laravel team make completely opposite choices for Go and Rust? Because they did not mechanically port PHP idioms across languages — they translated Laravel's philosophy into the native grain of each language.

At a Glance: PHP vs Go vs Rust
| Dimension | Laravel PHP | Laravel Go (v0.2.0) |
Laravel Rust (0.2.0) |
|---|---|---|---|
| DI Container | Yes (Reflection auto-wiring) | No (Explicit Services struct) |
Yes (Type-safe container) |
| Registration | AppServiceProvider (singleton / bind) |
services.New(env, app) in services/services.go |
app.singleton / app.bind / #[singleton] |
| Handler Access | Constructor or method injection | services.From(r) via context.Context |
Inject<T> / Inject<dyn Trait> extractor |
| Built-in Subsystems | Facades / Helpers / Container | Context helpers (db.Table, mail.To, config.From) |
Task-local helpers (laravel::mail::to, etc.) |
| Per-Request Scope | scoped() / bind() |
Manual / Middleware | app.bind(async |app| ...) |
| Dependency Visibility | Visible in signature | Hidden behind r (context.Context) |
Visible in signature (Inject<T>) |
| Test Isolation | Fresh container per test | Isolated App & Services per tests.New(t) |
Isolated container & swappable services |
Side-by-Side Code: Wiring a Stripe Client
In all three frameworks, built-in subsystems (database, cache, mailer, queues) are already wired by the framework. The real architectural divergence shows up when you add your own application service, such as a Stripe billing client.
1. Laravel PHP — Reflection Auto-Wiring
In PHP, you bind the service in a Service Provider (or let Laravel auto-wire concrete classes with zero configuration) and type-hint it directly in your controller:
// app/Providers/AppServiceProvider.php
$this->app->singleton(Stripe::class, function () {
return new Stripe(config('services.stripe.key'));
});
// app/Http/Controllers/ChargeController.php
public function store(Request $request, Stripe $stripe)
{
$stripe->charge(500);
}
- Strength: Zero boilerplate. Runtime swapping (
$this->app->instance(...)), scoped bindings, and contextual binding (when()->needs()->give()) are first-class. - Cost: Resolution happens dynamically at runtime; missing bindings surface when code runs rather than at compile time.
2. Laravel Go (v0.2.0) — Explicit Services Struct + Context
Laravel Go intentionally avoids reflection-based containers. Instead, your app defines a plain Services struct in services/services.go, wires every dependency by hand in services.New, and registers the constructor once in bootstrap/app.go:
// services/services.go
package services
import (
"context"
laravel "go.laravel.com"
"go.laravel.com/config"
"app/billing"
)
type Services struct {
Stripe *billing.Client
}
func New(env *config.Env, app *laravel.App) Services {
return Services{
Stripe: billing.NewClient(env.String("STRIPE_KEY", "")),
}
}
func From(ctx context.Context) *Services {
return laravel.ServicesOf[*Services](ctx)
}
// bootstrap/app.go
Services: laravel.BuildServices(services.New),
// handlers/charges/store.go
func Store(r *web.Request) web.Response {
if err := services.From(r).Stripe.Charge(r, 500); err != nil {
return web.Error(err)
}
return web.NoContent()
}
Notice two crucial details in Laravel Go's design:
- Service-to-service dependencies are plain Go arguments. If
billing.Clientneeds atax.Calculator, you buildtaxCalculatorfirst inservices.Newand pass it intobilling.NewClient(...). The Go compiler catches missing arguments before your binary even compiles. - No global variables.
*Servicesis attached to theAppinstance and retrieved throughcontext.Context, so parallel tests viatests.New(t)each receive their own isolatedServicesstruct.
3. Laravel Rust (0.2.0) — Type-Safe Service Container + Inject<T>
Laravel Rust takes the opposite route from Go — and embraces Rust's type system and Axum's extractor pattern:
// src/app.rs
pub fn configure() -> ApplicationBuilder {
Application::configure().with_services(|app| {
app.singleton(async |app| {
let key = &app.config().section::<StripeConfig>().key;
Ok(Stripe::new(key))
});
})
}
// src/handlers/charges.rs
pub async fn store(stripe: Inject<Stripe>) -> laravel::Result<Response> {
stripe.charge(500).await?;
Ok(response::no_content())
}
Laravel Rust's container supports:
app.singleton(...)— lazy initialization on first request, shared viaArc<T>.app.bind(...)— builds a fresh instance per resolution (ideal for per-request tenant or user context).singleton_as/bind_as— bind implementations behindInject<dyn Geocoder>trait contracts.#[singleton]/#[bind]attributes — register services right next to their definitions.- Lazy by default — if nothing requests a service, its factory never runs.
Why Go and Rust Diverged
Both decisions make complete sense once you look at each language's mechanics and culture:
- Why Go skipped the container: Go HTTP handlers have a fixed signature (
func(r *web.Request) web.Response), so arbitrary typed parameter extractors aren't idiomatic in Go. More importantly, the Go ecosystem strongly prefers explicit constructor wiring in one visible Composition Root over runtime container magic. - Why Rust built a container: Rust's generics,
TypeId, procedural macros, and Axum-style extractors makeInject<Stripe>feel completely natural. Instead of passing one giantState<AppState>struct into every handler, each handler declares only the services it actually uses.
This is the strongest signal yet that Laravel Go and Laravel Rust are not mechanical translations of Laravel PHP.
The Real Trade-Offs of Dropping DI in Laravel Go
Giving up a DI container in Go isn't free. After building both applications and an open-source admin package (Asaka) on Laravel Go, five concrete trade-offs stand out:

- Dependencies disappear from function signatures. Because
services.From(r)anddb.Table(r, ...)can pull anything out ofcontext.Context, you can no longer tell from a handler's signature whether it touches the database, sends mail, or charges Stripe. - Import cycles in domain packages. Because
servicesimports your domain packages to construct them, those domain packages cannot callservices.From(ctx)without triggering a Go import cycle. Even the official Laravel Go docs include an "Avoiding import cycles" section explaining why you should pass dependencies explicitly into domain functions. Servicescan become a god struct. In very large applications,services/services.gocollects every client and SDK in one place unless you deliberately group fields into cohesive sub-structs.- No built-in
scopedor contextual bindings. Anything that needs per-request state or conditional implementations requires explicit middleware or factory methods. - Testing leans toward feature tests. Pulling dependencies from
ctxmeans calling a function with a barecontext.Background()in a unit test can hit uninitialized state. Laravel Go's answer — spinning up an isolated app per test withtests.New(t)and subsystem fakes (mailtest,queuetest) — works great, but favors feature tests over pure mock-heavy unit tests.
Practical Verdict: Apps vs. Packages
So should the lack of a DI container worry you if you're adopting Laravel Go? It depends on what you're building:
- For business applications & AI-assisted development: Laravel Go's explicit
Servicesstruct is often a net win. Small teams — and AI coding agents — make far fewer mistakes when the entire dependency graph is plain Go code in one file with compile-time checking and zero hidden service-provider boot order surprises. Keepservices.From(r)at the handler boundary, and pass concrete dependencies explicitly into your domain packages. - For OSS / library authors: This is where you feel the difference most. In Filament PHP, users could override internal package classes through Laravel's container (
app()->bind(...)). In Laravel Go, there is no container backdoor — so as a package author, you must design your extension points up front using clean Go interfaces and Functional Options (With...). The upside? Users can't silently monkey-patch your internals, which makes long-term maintenance and upgrades significantly safer.
Same Laravel philosophy. Three distinct languages. And each one chose the dependency model that fits its compiler and its community best.