ioc

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 5 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(target any) (err error)

func Call

func Call(fn any) (err error)

func Find

func Find[T any](name string) T

func Put

func Put(builder any, opts ...Option)

func Range

func Range(fn func(name string, service any) bool)

func TryFind

func TryFind[T any](name string) (t T, err error)

Types

type Container

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

func New

func New() *Container

func (*Container) Bind

func (c *Container) Bind(target any) error

Bind fills struct fields with specific services.

func (*Container) Call

func (c *Container) Call(fn any) error

Call invoke fn with specified services as it's params.

func (*Container) Find

func (c *Container) Find(name string) any

Find returns the service instance with the specified name.

func (*Container) Put

func (c *Container) Put(builder any, opts ...Option)

Put registers the service to container.

func (*Container) Range

func (c *Container) Range(fn func(name string, service any) bool)

Range calls fn sequentially for each service present in the map. If fn returns false, range stops the iteration.

func (*Container) TryFind

func (c *Container) TryFind(name string) (any, error)

TryFind returns the service instance with the specified name.

type Option

type Option func(opts *service)

func Group

func Group(group string) Option

Group set service's group.

func Name

func Name(name string) Option

Name set service's name.

func Scope

func Scope(singleton bool) Option

Scope set service's scope.

Jump to

Keyboard shortcuts

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