container

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SharedScope    = "shared"
	PrototypeScope = "prototype"
)

Variables

This section is empty.

Functions

func Register

func Register(constructor Constructor, options ...Option)

Types

type Constructor

type Constructor any

type Container

type Container interface {
	Start() error
	DefinitionRegistry() DefinitionRegistry
	SharedInstances() SharedInstances
	Hooks() Hooks
	Get(ctx context.Context, name string) (any, error)
	GetByNameAndType(ctx context.Context, name string, typ reflector.Type) (any, error)
	GetByNameAndArgs(ctx context.Context, name string, args ...any) (any, error)
	GetByType(ctx context.Context, typ reflector.Type) (any, error)
	GetInstancesByType(ctx context.Context, requiredType reflector.Type) ([]any, error)
	Contains(name string) bool
	IsShared(name string) bool
	IsPrototype(name string) bool
	RegisterResolvable(typ reflector.Type, object any) error
	ScopeNames() []string
	GetScope(scopeName string) (Scope, error)
}

func New

func New() Container

func WithDefinitions

func WithDefinitions(definitions []*Definition) Container

type Definition

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

func MakeDefinition

func MakeDefinition(constructor Constructor, options ...Option) (*Definition, error)

func RegisteredDefinitions

func RegisteredDefinitions() []*Definition

func (*Definition) Constructor

func (d *Definition) Constructor() reflector.Function

func (*Definition) Inputs

func (d *Definition) Inputs() []*Input

func (*Definition) IsPrototype

func (d *Definition) IsPrototype() bool

func (*Definition) IsShared

func (d *Definition) IsShared() bool

func (*Definition) Name

func (d *Definition) Name() string

func (*Definition) Scope

func (d *Definition) Scope() string

func (*Definition) Type

func (d *Definition) Type() reflector.Type

type DefinitionRegistry

type DefinitionRegistry interface {
	Register(def *Definition) error
	Remove(name string) error
	Contains(name string) bool
	Find(name string) (*Definition, bool)
	Definitions() []*Definition
	DefinitionNames() []string
	DefinitionNamesByType(requiredType reflector.Type) []string
	Count() int
}

func NewDefinitionRegistry

func NewDefinitionRegistry(defs []*Definition) DefinitionRegistry

type Hook

type Hook struct {
	OnPreInitialization  func(string, any) (any, error)
	OnPostInitialization func(string, any) (any, error)
}

func PostInitialization

func PostInitialization[F HookFunc](f F) *Hook

func PreInitialization

func PreInitialization[F HookFunc](f F) *Hook

type HookFunc

type HookFunc interface {
	func(name string, instance any) (any, error)
}

type Hooks

type Hooks interface {
	Add(hook *Hook) error
	Remove(hook *Hook)
	RemoveAll()
	ToSlice() []*Hook
	Count() int
}

func NewHooks

func NewHooks() Hooks

type Input

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

func (*Input) Index

func (i *Input) Index() int

func (*Input) IsOptional

func (i *Input) IsOptional() bool

func (*Input) Name

func (i *Input) Name() string

func (*Input) Type

func (i *Input) Type() reflector.Type

type Option

type Option func(def *Definition) error

func Name

func Name(name string) Option

func Optional

func Optional[T any]() Option

func OptionalAt

func OptionalAt(index int) Option

func Qualifier

func Qualifier[T any](name string) Option

func QualifierAt

func QualifierAt(index int, name string) Option

func Scoped

func Scoped(scope string) Option

type PostConstructor

type PostConstructor interface {
	PostConstruct() error
}

type PostInitializationHook

type PostInitializationHook interface {
	OnPostInitialization(name string, instance any) (any, error)
}

type PreInitializationHook

type PreInitializationHook interface {
	OnPreInitialization(name string, instance any) (any, error)
}

type Scope

type Scope interface {
	GetObject(ctx context.Context, name string, supplier func(ctx context.Context) (any, error)) (any, error)
	RemoveObject(ctx context.Context, name string) (any, error)
}

type SharedInstances

type SharedInstances interface {
	Register(name string, instance any) error
	Find(name string) (any, bool)
	Contains(name string) bool
	InstanceNames() []string
	FindByType(requiredType reflector.Type) (any, error)
	FindAllByType(requiredType reflector.Type) []any
	OrElseGet(name string, supplier func() (any, error)) (any, error)
	Count() int
}

func NewSharedInstances

func NewSharedInstances() SharedInstances

Jump to

Keyboard shortcuts

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