contract

package
v3.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container interface {
	Registrar

	Resolver

	OverrideService

	ScopeManager

	Names() []string

	Close() error
}

type OverrideService

type OverrideService interface {
	OverrideInstance(serviceName string, value any) error

	MustOverrideInstance(serviceName string, value any)

	OverrideProtectedInstance(serviceName string, value any) error

	MustOverrideProtectedInstance(serviceName string, value any)
}

type Provider

type Provider[T any] func(resolver Resolver) (T, error)

type RegisterOption

type RegisterOption func(option *RegisterOptions)

type RegisterOptions

type RegisterOptions struct {
	AlsoRegisterType         bool
	TypeRegistrationIsStrict bool
	/* CollectionPriority orders this registration inside AllImplementing collections: a higher priority is collected earlier. Registrations sharing a priority keep the stable type-and-name order. */
	CollectionPriority int
}

type Registrar

type Registrar interface {
	Register(serviceName string, provider any, options ...RegisterOption) error

	MustRegister(serviceName string, provider any, options ...RegisterOption)
}

type Resolver

type Resolver interface {
	Get(serviceName string) (any, error)

	MustGet(serviceName string) any

	GetByType(targetType reflect.Type) (any, error)

	MustGetByType(targetType reflect.Type) any

	Has(serviceName string) bool

	HasType(targetType reflect.Type) bool
}

type Scope

type Scope interface {
	Resolver

	OverrideService

	Close() error
}

type ScopeManager

type ScopeManager interface {
	NewScope() Scope
}

type ServiceReference added in v3.12.0

type ServiceReference struct {
	ServiceName string
	ServiceType reflect.Type
}

ServiceReference identifies one registered service the way the container itself addresses it: by the name it was registered under, together with the canonical type of that registration. A type registered under several names yields one reference per name, so a consumer that collects services reaches every instance instead of failing on the ambiguity of the type alone.

type TypeLister added in v3.12.0

type TypeLister interface {
	TypesImplementing(interfaceType reflect.Type) []reflect.Type

	/* ReferencesImplementing lists every registration whose type satisfies the interface, one reference per registered name, ordered by descending collection priority and then by type and name so a collection never reorders between runs. */
	ReferencesImplementing(interfaceType reflect.Type) []ServiceReference
}

TypeLister is implemented by a resolver that can enumerate the service types it holds. It stays apart from Resolver so that a resolver written outside the framework keeps working without it, and so a consumer that needs the capability has to ask for it explicitly.

Jump to

Keyboard shortcuts

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