di

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package di provides the dependency injection container for clean-wizard, built on samber/do v2. It centralizes all service registration and lifecycle management, replacing the former hand-wired dual-registry approach.

The container is created once at application startup, services are registered via RegisterAllServices, and the returned cleanup function ensures graceful shutdown of all services implementing do.ShutdownerWithError.

Index

Constants

This section is empty.

Variables

View Source
var CleanerPackage = do.Package(
	registerCleanerRegistry,
)

CleanerPackage groups all cleaner-related provider registrations. Using do.Package keeps the registration organized and composable, matching BuildFlow's InfrastructurePackage / ApplicationPackage pattern.

Functions

func CleanerRegistry

func CleanerRegistry(i do.Injector) (*cleaner.Registry, error)

CleanerRegistry resolves the cleaner registry from the DI container. The registry is lazily created on first invocation with the registered RunSettings.

func Config

func Config(i do.Injector) (*domain.Config, error)

Config resolves the application configuration from the DI container.

func OverrideRegistry

func OverrideRegistry(injector do.Injector, replacement *cleaner.Registry)

OverrideRegistry replaces the cleaner registry in the DI container with a test double. This enables tests to inject mock or pre-configured registries without modifying the production registration logic.

func OverrideSettings

func OverrideSettings(injector do.Injector, settings RunSettings)

OverrideSettings replaces the run settings in the DI container with test values.

func RegisterAllServices

func RegisterAllServices(injector do.Injector, cfg *domain.Config, settings RunSettings) error

RegisterAllServices wires every application service into the DI container. It registers the already-loaded config and run settings as eager values, then invokes the provider packages for lazy service creation.

This is the single entry point for service registration, mirroring BuildFlow's di.RegisterAllServices pattern.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container wraps a samber/do injector with lifecycle management. It is the single entry point for resolving any service in the application.

func New

func New() (*Container, func())

New creates a fresh Container with an empty injector. The returned cleanup function must be deferred to ensure all services implementing do.ShutdownerWithError are gracefully stopped.

func (*Container) Injector

func (c *Container) Injector() do.Injector

Injector exposes the underlying samber/do injector for direct use with do.Provide, do.Invoke, etc.

func (*Container) Shutdown

func (c *Container) Shutdown() *do.ShutdownReport

Shutdown gracefully shuts down all registered services.

type RunSettings

type RunSettings struct {
	Verbose        bool
	DryRun         bool
	MaxConcurrency int
}

RunSettings holds the runtime flags parsed from the CLI. These are registered as an eager value in the DI container so that all cleaner providers can resolve them lazily.

func Settings

func Settings(i do.Injector) (RunSettings, error)

Settings resolves the runtime settings (verbose, dryRun) from the DI container.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL