extended

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

extended contains container extensions like DerivedContainer or MustContainer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Derived

func Derived(parent pkg.Container) pkg.Container

Types

type DerivedContainer

type DerivedContainer struct {
	pkg.Container
	// contains filtered or unexported fields
}

func (*DerivedContainer) Fill

func (d *DerivedContainer) Fill(structure any) error

Fill implements pkg.Container.

func (*DerivedContainer) HasToken

func (d *DerivedContainer) HasToken(token string) bool

HasToken implements pkg.Container.

func (*DerivedContainer) HasType

func (d *DerivedContainer) HasType(refType reflect.Type) bool

HasType implements pkg.Container.

func (*DerivedContainer) Resolve

func (d *DerivedContainer) Resolve(value any) error

Resolve implements pkg.Container.

func (*DerivedContainer) ResolveToken

func (d *DerivedContainer) ResolveToken(token string, value any) error

ResolveToken implements pkg.Container.

type MustContainer

type MustContainer interface {

	// Singleton sets a dependency as a [wiring.] dependency.
	// Once the abstraction is instanciated this instance will be cached and
	// will no longer create new instances
	Singleton(resolver any)
	// Transient sets a dependency as a transient dependency.
	// Every time the container is asked to resolve an abstraction
	// the container will create a new instance of that dependency
	Transient(resolver any)
	// Resolve given a pointer to value it will be resolved and the container
	// will update the referenced value with the instance resolved
	Resolve(value any)

	// SingletonToken same as Singleton but instead of using the type to identify
	// the implementation it uses the token
	SingletonToken(token string, resolver any)
	// TransientToken same as Transient but instead of using the type to identify
	// the implementation it uses the token
	TransientToken(token string, resolver any)
	// Gets the instance associated with the provided token
	ResolveToken(token string, value any)

	// Fill gets a struct pointer and resolves their fields, if the field needs to be resolved by token
	// you can use the 'wire' tag with the token that is associated with. If the field needs to be ignored
	// use the ignore param -> wire:",ignore". Unexported fields will be ignored
	Fill(structure any)

	// Check if the container has a resolver for that type
	HasType(refType reflect.Type) bool
	// Check if the container has a resolver for that token
	HasToken(token string) bool
}

MustContainer is a container which instead of returing errors it panics use it for prototyping or in circumstances where you know that resolvers are extremerly well configured.

func Must

func Must(container pkg.Container) MustContainer

Jump to

Keyboard shortcuts

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