Dependency Injection
GoForj uses explicit Go constructors and Wire-generated code. It does not use a runtime service locator.
Each app has its own Wire graph.
The Model
Application packages own constructors:
func NewService(repo *Repository) *Service {
return &Service{repo: repo}
}The app's Wire package assembles those constructors:
internal package -> app/wire provider set -> app/wire/wire_gen.go -> appFor a named app, the graph lives under app/<name>/wire.
Where It Lives
Default app:
app/wire/
wire.go
wire_gen.go
inject_cmd_app.go
inject_http_controllers_app.go
inject_services_app.goNamed app:
app/marketplace/wire/
wire.go
wire_gen.go
inject_cmd_app.go
inject_http_controllers_app.go
inject_services_app.goGenerated files appear only when the selected components need them.
Provider Sets
Provider sets group constructors for a specific app surface:
- application services
- repositories
- HTTP controllers
- commands
- jobs
- schedules
- subscribers
- framework managers
The order inside wire.NewSet is not construction order. Wire reads the whole graph, matches types, and writes ordinary Go code to wire_gen.go.
Construction Boundary
Wire constructs the app. It does not start long-running runtime work.
Construction can allocate services, adapters, managers, controllers, commands, and registries. HTTP servers, queue workers, and schedulers start when a command starts that runtime.
Regenerate Wiring
Run the build pipeline after changing providers, generated components, or Wire sets:
forj buildFor a named app:
forj marketplace buildDev Loop
forj dev normally runs the build path through each App lifecycle listed under dev.apps. In a multi-app Project, unqualified forj dev manages every listed App.
Common Mistakes
Common mistakes
- Do not use package globals to hide dependencies from Wire.
- Do not edit
wire_gen.goby hand. - Do not add nil guards around required constructor-injected dependencies.
- Do not put business workflows in provider functions.
Next Steps
- Providers defines provider functions.
- Wiring Recipes shows which app-local file to edit.
- Reading Wire Errors explains common Wire failures.
