Skip to content

kibuwire

kibuwire - Dependency Injection Provider Registration

kibuwire analyzes Go code for provider annotations and generates Google Wire dependency injection configuration files. It automates the tedious process of managing Wire sets across large codebases.

Installation

Terminal window
go install github.com/kibu-sh/kibu/internal/toolchain/kibuwire/cmd/kibuwire@main
go install github.com/google/wire/cmd/wire@latest

Purpose

kibuwire solves the problem of managing Wire provider sets at scale by:

  1. Scanning for //kibu:provider decorators on functions, structs, and variables
  2. Extracting provider metadata including group assignments and import paths
  3. Generating organized Wire sets by group and package
  4. Creating a SuperSet that combines all providers for easy injection

Usage

Add a go:generate directive to your project:

package generate
//go:generate kibuwire ./...

Then run:

Terminal window
go generate ./...

This produces kibuwire/kibuwire.gen.go containing all Wire sets.

The Provider Decorator

Basic Syntax

//kibu:provider [options]

Options

OptionDescriptionExample
importPackage import path for the provider interfaceimport=github.com/kibu-sh/kibu/pkg/transport/httpx
groupProvider group name for aggregationgroup=HandlerFactory

Examples

Simple Provider Function

//kibu:provider
func NewDatabase(cfg *Config) (*sql.DB, error) {
return sql.Open("postgres", cfg.DSN)
}

Provider with Group

//kibu:provider import=github.com/kibu-sh/kibu/pkg/transport/httpx group=HandlerFactory
type UserServiceController struct {
impl UserService
}

Provider Variable (Wire Set)

//kibu:provider
var ServiceWireSet = wire.NewSet(
NewUserService,
NewOrderService,
)

Generated Output

kibuwire generates several types of Wire sets:

Package Wire Sets

For each package with providers, a wire set is generated:

var HealthWireSet = wire.NewSet(
health.NewService,
wire.Struct(new(health.ServiceController), "*"),
)

Group Sets

Providers with the same group option are aggregated:

var HttpxHandlerFactoryGroup = wire.NewSet(
health.ServiceControllerWireSet,
users.ServiceControllerWireSet,
orders.ServiceControllerWireSet,
)

Group Provider Functions

Functions that return slices of group interfaces:

func ProvideHttpxHandlerFactoryGroup(
healthCtrl *health.ServiceController,
usersCtrl *users.ServiceController,
ordersCtrl *orders.ServiceController,
) []httpx.HandlerFactory {
return []httpx.HandlerFactory{
healthCtrl,
usersCtrl,
ordersCtrl,
}
}

SuperSet

A master wire set combining everything:

var SuperSet = wire.NewSet(
HealthWireSet,
UsersWireSet,
OrdersWireSet,
HttpxHandlerFactoryGroup,
ProvideHttpxHandlerFactoryGroup,
)

Common Provider Groups

GroupInterfacePurpose
HandlerFactoryhttpx.HandlerFactoryHTTP route handlers
WorkerFactorytemporal.WorkerFactoryTemporal workers
ActivityFactorytemporal.ActivityFactoryTemporal activities
WorkflowFactorytemporal.WorkflowFactoryTemporal workflows

Integration with kibugenv2

kibugenv2 automatically adds //kibu:provider decorators to generated controllers:

// Generated by kibugenv2
//kibu:provider import=github.com/kibu-sh/kibu/pkg/transport/httpx group=HandlerFactory
type HealthServiceController struct {
impl HealthService
}

This creates a seamless pipeline:

  1. Define service interfaces with //kibu:service
  2. Run kibugenv2 to generate controllers with provider annotations
  3. Run kibuwire to aggregate providers into Wire sets

Example Workflow

Step 1: Define Services

src/backend/systems/health/health.go
package health
//kibu:service
type Service interface {
//kibu:service:method method=GET
Check(ctx context.Context, req CheckRequest) (CheckResponse, error)
}

Step 2: Generate Plumbing

Terminal window
kibugenv2 ./...

This creates health.gen.go with:

//kibu:provider import=github.com/kibu-sh/kibu/pkg/transport/httpx group=HandlerFactory
type ServiceController struct { ... }

Step 3: Generate Wire Sets

Terminal window
kibuwire ./...

This creates kibuwire/kibuwire.gen.go with organized Wire sets.

Step 4: Use in Main

cmd/server/wire.go
//go:build wireinject
package main
import (
"github.com/google/wire"
"example/kibuwire"
)
func InitializeApp() (*App, error) {
wire.Build(
kibuwire.SuperSet,
NewApp,
)
return nil, nil
}

Project Structure

After running kibuwire, your project will have:

project/
├── src/backend/systems/
│ ├── health/
│ │ ├── health.go
│ │ └── health.gen.go
│ └── users/
│ ├── users.go
│ └── users.gen.go
├── kibuwire/
│ └── kibuwire.gen.go # Generated Wire sets
└── generate.go

Best Practices

  1. Use groups consistently: All HTTP handlers should use group=HandlerFactory
  2. Don’t edit generated files: kibuwire/kibuwire.gen.go is regenerated on each run
  3. Run after kibugenv2: Provider annotations come from generated code
  4. Import the SuperSet: Use kibuwire.SuperSet in your Wire injector for full coverage

Troubleshooting

Missing providers in SuperSet

Ensure all packages with //kibu:provider annotations are included in the ./... glob pattern.

Import errors

Check that the import= option points to a valid package path with the expected interface.

Wire build failures

Run wire check ./... to diagnose Wire-specific issues after generating with kibuwire.