Documentation
¶
Overview ¶
Package bean provides typed, reflection-free dependency handles used by generated Spice applications.
Index ¶
- func RequestScopeMiddleware(next http.Handler, onError ScopeErrorHandler) (http.Handler, error)
- func WithScope(ctx context.Context, scope *Scope) (context.Context, error)
- type AcquireFunc
- type Lazy
- type Optional
- type Override
- type OverrideFactory
- type Provider
- type Scope
- type ScopeErrorHandler
- type ScopeKind
- type Scoped
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestScopeMiddleware ¶
RequestScopeMiddleware creates and closes one scope per HTTP request.
Types ¶
type AcquireFunc ¶
AcquireFunc constructs or leases one typed bean.
type Lazy ¶
type Lazy[T any] struct { // contains filtered or unexported fields }
Lazy resolves one typed value at most once. The first result, including an error, is stable for the lifetime of the owning generated scope.
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
Optional contains either one unambiguous typed bean or no bean. Ambiguity is rejected by the compiler and can never be represented at runtime.
type Override ¶
type Override[T any] struct { // contains filtered or unexported fields }
Override is an explicit typed replacement for one generated singleton bean. Its zero value is disabled, so production ApplicationOptions remain concise.
func ReplaceFactory ¶
func ReplaceFactory[T any](factory OverrideFactory[T]) Override[T]
ReplaceFactory returns an enabled override with caller-owned construction and cleanup. A nil factory fails when the generated application is constructed.
type OverrideFactory ¶
OverrideFactory constructs one test- or embedding-owned replacement bean. Generated applications register returned cleanup in the original bean's module lifecycle and never place the value in a runtime container.
type Provider ¶
type Provider[T any] struct { // contains filtered or unexported fields }
Provider is an explicit typed acquisition handle. It contains no global registry and performs no reflection or string lookup.
func NewProvider ¶
func NewProvider[T any](acquire AcquireFunc[T]) Provider[T]
NewProvider constructs a typed provider handle.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope owns cleanup leases in reverse construction order.
type ScopeErrorHandler ¶
ScopeErrorHandler observes request-scope cleanup failures.
type Scoped ¶
type Scoped[T any] struct { // contains filtered or unexported fields }
Scoped is a typed generated-scope factory. Each instance represents exactly one bean declaration, so lookup never uses a runtime bean name.