Documentation
¶
Index ¶
- func DefaultInjector() do.Injector
- func Invoke[T any](ctx Context) (T, error)
- func InvokeDefault[T any]() (T, error)
- func MustInvoke[T any](ctx Context) T
- func MustInvokeDefault[T any]() T
- func PriorityOf(provider Provider) int
- func Provide[T any](ctx Context, constructor func(do.Injector) (T, error))
- func ProvideDefault[T any](ctx Context, constructor func(do.Injector) (T, error))
- func ProvideValue[T any](ctx Context, value T)
- func ProvideValueOnce[T any](ctx Context, value T)
- func ProvideValueOnceTo[T any](injector do.Injector, value T)
- func SetDefaultInjector(injector do.Injector)
- type Base
- type Context
- type Module
- type ModuleBase
- type ModuleDepends
- type Ordered
- type Provider
- type Resolver
- type RouteServiceBinder
- type Service
- type ServiceBase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultInjector ¶
DefaultInjector returns the process-wide default dependency container.
func InvokeDefault ¶
InvokeDefault resolves a dependency from the default container.
func MustInvoke ¶
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 ¶
PriorityOf returns a provider's priority. Lower values run earlier.
func ProvideDefault ¶
ProvideDefault registers a lazy dependency only when it has not already been registered.
func ProvideValue ¶
ProvideValue registers an eager dependency value on the provider context.
func ProvideValueOnce ¶
ProvideValueOnce registers an eager dependency value only when it has not already been registered.
func ProvideValueOnceTo ¶
ProvideValueOnceTo registers an eager dependency value on an injector only when absent.
func SetDefaultInjector ¶
SetDefaultInjector sets the process-wide default dependency container.
Types ¶
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 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 ¶
Resolver runs after all providers, services, and modules have registered and before any provider boot hook starts.
type RouteServiceBinder ¶
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.