di

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package di exposes shared dependency injection helpers for KSail commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveClusterProvisionerFactory

func ResolveClusterProvisionerFactory(
	injector Injector,
) (clusterprovisioner.Factory, error)

ResolveClusterProvisionerFactory retrieves the cluster provisioner factory dependency.

func ResolveTimer

func ResolveTimer(injector Injector) (timer.Timer, error)

ResolveTimer retrieves the timer dependency from the injector with consistent error handling.

func RunEWithRuntime

func RunEWithRuntime(
	runtimeContainer *Runtime,
	handler func(cmd *cobra.Command, injector Injector) error,
) func(*cobra.Command, []string) error

RunEWithRuntime returns a cobra RunE function that resolves dependencies using the provided runtime container. The handler is executed with the active command and resolved injector when the command runs.

func WithTimer

func WithTimer(
	handler func(cmd *cobra.Command, injector Injector, tmr timer.Timer) error,
) func(cmd *cobra.Command, injector Injector) error

WithTimer decorates a handler to automatically resolve the timer dependency.

Types

type Injector

type Injector = do.Injector

Injector is an alias for the underlying DI container implementation.

type Module

type Module func(do.Injector) error

Module registers dependencies with the DI container.

type Runtime

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

Runtime owns shared dependency registration for Cobra commands.

func New

func New(modules ...Module) *Runtime

New constructs a Runtime with the provided base modules. Modules are applied in the order supplied when invoking commands.

func NewRuntime

func NewRuntime() *Runtime

NewRuntime constructs the shared runtime container used by root command and tests.

func (*Runtime) Invoke

func (r *Runtime) Invoke(
	handler func(Injector) error,
	extraModules ...Module,
) error

Invoke builds a fresh injector, applies base and extra modules, and executes the provided function.

Jump to

Keyboard shortcuts

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