provider

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultInjector

func DefaultInjector() do.Injector

DefaultInjector returns the process-wide default dependency container.

func Invoke

func Invoke[T any](ctx Context) (T, error)

Invoke resolves a dependency from the provider context.

func InvokeDefault

func InvokeDefault[T any]() (T, error)

InvokeDefault resolves a dependency from the default container.

func MustInvoke

func MustInvoke[T any](ctx Context) T

MustInvoke resolves a dependency from the provider context or panics.

func MustInvokeDefault

func MustInvokeDefault[T any]() T

MustInvokeDefault resolves a dependency from the default container or panics.

func PriorityOf

func PriorityOf(provider Provider) int

PriorityOf returns a provider's priority. Lower values run earlier.

func Provide

func Provide[T any](ctx Context, constructor func(do.Injector) (T, error))

Provide registers a lazy dependency constructor on the provider context.

func ProvideDefault

func ProvideDefault[T any](ctx Context, constructor func(do.Injector) (T, error))

ProvideDefault registers a lazy dependency only when it has not already been registered.

func ProvideValue

func ProvideValue[T any](ctx Context, value T)

ProvideValue registers an eager dependency value on the provider context.

func ProvideValueOnce

func ProvideValueOnce[T any](ctx Context, value T)

ProvideValueOnce registers an eager dependency value only when it has not already been registered.

func ProvideValueOnceTo

func ProvideValueOnceTo[T any](injector do.Injector, value T)

ProvideValueOnceTo registers an eager dependency value on an injector only when absent.

func SetDefaultInjector

func SetDefaultInjector(injector do.Injector)

SetDefaultInjector sets the process-wide default dependency container.

Types

type Base

type Base struct{}

Base provides no-op lifecycle methods for provider implementations.

func (Base) Boot

func (Base) Boot(context.Context, Context) error

func (Base) Init

func (Base) Init(context.Context, Context) error

func (Base) Priority

func (Base) Priority() int

func (Base) Register

func (Base) Register(Context) error

func (Base) Shutdown

func (Base) Shutdown(context.Context, Context) error

type Context

type Context interface {
	// App returns the concrete application object for packages that intentionally
	// need app-level route, lifecycle, or infrastructure APIs.
	App() any
	// Injector returns the application DI container.
	Injector() do.Injector
	// RegisterCommand registers CLI commands without depending on the root package.
	RegisterCommand(commands ...command.Command) error
	// RegisterService registers lifecycle services without depending on the root package.
	RegisterService(services ...any) error
	// RegisterModule registers business modules without depending on the root package.
	RegisterModule(modules ...any) error
	// RegisterHost registers host units without depending on the root package.
	RegisterHost(units ...host.Unit) error
	// RegisterRouteService exposes app-scoped services to route contexts without
	// making the runtime package depend on individual subsystem packages.
	RegisterRouteService(services ...any) error
}

Context is passed to providers during application freeze.

type Module

type Module interface {
	Name() string
	Init(ctx context.Context, app Context) error
	Register(ctx context.Context, app Context) error
	Boot(ctx context.Context, app Context) error
	Shutdown(ctx context.Context, app Context) error
}

Module is a business module entry.

type ModuleBase

type ModuleBase struct{}

ModuleBase provides no-op lifecycle methods for modules.

func (ModuleBase) Boot

func (ModuleBase) Init

func (ModuleBase) Register

func (ModuleBase) Register(context.Context, Context) error

func (ModuleBase) Shutdown

func (ModuleBase) Shutdown(context.Context, Context) error

type ModuleDepends

type ModuleDepends interface {
	Depends() []string
}

ModuleDepends lets a module declare hard dependencies by module name.

type Ordered

type Ordered interface {
	Priority() int
}

Ordered lets a provider run before or after other providers.

type Provider

type Provider interface {
	Name() string
	Init(ctx context.Context, app Context) error
	Register(ctx Context) error
	Boot(ctx context.Context, app Context) error
	Shutdown(ctx context.Context, app Context) error
}

Provider is the extension contract managed by the application lifecycle.

type Resolver

type Resolver interface {
	Resolve(ctx context.Context) error
}

Resolver runs after all providers, services, and modules have registered and before any provider boot hook starts.

type RouteServiceBinder

type RouteServiceBinder interface {
	RegisterRouteService(services ...any) error
}

RouteServiceBinder accepts app-scoped services for route-like transports without making the runtime package depend on a transport implementation.

type Service

type Service interface {
	Name() string
	Init(ctx context.Context, app Context) error
	Register(ctx context.Context, app Context) error
	Boot(ctx context.Context, app Context) error
	Shutdown(ctx context.Context, app Context) error
}

Service is a framework or infrastructure capability with lifecycle hooks.

type ServiceBase

type ServiceBase struct{}

ServiceBase provides no-op lifecycle methods for services.

func (ServiceBase) Boot

func (ServiceBase) Init

func (ServiceBase) Register

func (ServiceBase) Shutdown

Jump to

Keyboard shortcuts

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