Documentation ¶
Overview ¶
Package container is a lightweight yet powerful IoC container for Go projects. It provides an easy-to-use interface and performance-in-mind container to be your ultimate requirement.
Index ¶
- Variables
- func Call(receiver interface{}) error
- func Fill(receiver interface{}) error
- func MustCall(c Container, receiver interface{})
- func MustFill(c Container, receiver interface{})
- func MustNamedResolve(c Container, abstraction interface{}, name string)
- func MustNamedSingleton(c Container, name string, resolver interface{})
- func MustNamedSingletonLazy(c Container, name string, resolver interface{})
- func MustNamedTransient(c Container, name string, resolver interface{})
- func MustNamedTransientLazy(c Container, name string, resolver interface{})
- func MustResolve(c Container, abstraction interface{})
- func MustSingleton(c Container, resolver interface{})
- func MustSingletonLazy(c Container, resolver interface{})
- func MustTransient(c Container, resolver interface{})
- func MustTransientLazy(c Container, resolver interface{})
- func NamedResolve(abstraction interface{}, name string) error
- func NamedSingleton(name string, resolver interface{}) error
- func NamedSingletonLazy(name string, resolver interface{}) error
- func NamedTransient(name string, resolver interface{}) error
- func NamedTransientLazy(name string, resolver interface{}) error
- func Reset()
- func Resolve(abstraction interface{}) error
- func Singleton(resolver interface{}) error
- func SingletonLazy(resolver interface{}) error
- func Transient(resolver interface{}) error
- func TransientLazy(resolver interface{}) error
- type Container
- func (c Container) Call(function interface{}) error
- func (c Container) Fill(structure interface{}) error
- func (c Container) NamedResolve(abstraction interface{}, name string) error
- func (c Container) NamedSingleton(name string, resolver interface{}) error
- func (c Container) NamedSingletonLazy(name string, resolver interface{}) error
- func (c Container) NamedTransient(name string, resolver interface{}) error
- func (c Container) NamedTransientLazy(name string, resolver interface{}) error
- func (c Container) Reset()
- func (c Container) Resolve(abstraction interface{}) error
- func (c Container) Singleton(resolver interface{}) error
- func (c Container) SingletonLazy(resolver interface{}) error
- func (c Container) Transient(resolver interface{}) error
- func (c Container) TransientLazy(resolver interface{}) error
Constants ¶
This section is empty.
Variables ¶
var Global = New()
Global is the global concrete of the Container.
Functions ¶
func Call ¶
func Call(receiver interface{}) error
Call calls the same method of the global concrete.
func Fill ¶
func Fill(receiver interface{}) error
Fill calls the same method of the global concrete.
func MustCall ¶ added in v3.2.0
func MustCall(c Container, receiver interface{})
MustCall wraps the `Call` method and panics on errors instead of returning the errors.
func MustFill ¶ added in v3.2.0
func MustFill(c Container, receiver interface{})
MustFill wraps the `Fill` method and panics on errors instead of returning the errors.
func MustNamedResolve ¶ added in v3.2.0
MustNamedResolve wraps the `NamedResolve` method and panics on errors instead of returning the errors.
func MustNamedSingleton ¶ added in v3.2.0
MustNamedSingleton wraps the `NamedSingleton` method and panics on errors instead of returning the errors.
func MustNamedSingletonLazy ¶ added in v3.3.0
MustNamedSingleton wraps the `NamedSingletonLazy` method and panics on errors instead of returning the errors.
func MustNamedTransient ¶ added in v3.2.0
MustNamedTransient wraps the `NamedTransient` method and panics on errors instead of returning the errors.
func MustNamedTransientLazy ¶ added in v3.3.0
MustNamedTransient wraps the `NamedTransientLazy` method and panics on errors instead of returning the errors.
func MustResolve ¶ added in v3.2.0
func MustResolve(c Container, abstraction interface{})
MustResolve wraps the `Resolve` method and panics on errors instead of returning the errors.
func MustSingleton ¶ added in v3.2.0
func MustSingleton(c Container, resolver interface{})
MustSingleton wraps the `Singleton` method and panics on errors instead of returning the errors.
func MustSingletonLazy ¶ added in v3.3.0
func MustSingletonLazy(c Container, resolver interface{})
MustSingleton wraps the `SingletonLazy` method and panics on errors instead of returning the errors.
func MustTransient ¶ added in v3.2.0
func MustTransient(c Container, resolver interface{})
MustTransient wraps the `Transient` method and panics on errors instead of returning the errors.
func MustTransientLazy ¶ added in v3.3.0
func MustTransientLazy(c Container, resolver interface{})
MustTransientLazy wraps the `TransientLazy` method and panics on errors instead of returning the errors.
func NamedResolve ¶
NamedResolve calls the same method of the global concrete.
func NamedSingleton ¶
NamedSingleton calls the same method of the global concrete.
func NamedSingletonLazy ¶ added in v3.3.0
NamedSingletonLazy calls the same method of the global concrete.
func NamedTransient ¶
NamedTransient calls the same method of the global concrete.
func NamedTransientLazy ¶ added in v3.3.0
NamedTransientLazy calls the same method of the global concrete.
func Resolve ¶
func Resolve(abstraction interface{}) error
Resolve calls the same method of the global concrete.
func Singleton ¶
func Singleton(resolver interface{}) error
Singleton calls the same method of the global concrete.
func SingletonLazy ¶ added in v3.3.0
func SingletonLazy(resolver interface{}) error
SingletonLazy calls the same method of the global concrete.
func Transient ¶
func Transient(resolver interface{}) error
Transient calls the same method of the global concrete.
func TransientLazy ¶ added in v3.3.0
func TransientLazy(resolver interface{}) error
TransientLazy calls the same method of the global concrete.
Types ¶
type Container ¶ added in v3.1.4
Container holds the bindings and provides methods to interact with them. It is the entry point in the package.
func (Container) Call ¶ added in v3.1.4
Call takes a receiver function with one or more arguments of the abstractions (interfaces). It invokes the receiver function and passes the related concretes.
func (Container) Fill ¶ added in v3.1.4
Fill takes a struct and resolves the fields with the tag `container:"inject"`
func (Container) NamedResolve ¶ added in v3.1.4
NamedResolve takes abstraction and its name and fills it with the related concrete.
func (Container) NamedSingleton ¶ added in v3.1.4
NamedSingleton binds a named abstraction to concrete in singleton mode.
func (Container) NamedSingletonLazy ¶ added in v3.3.0
NamedSingleton binds a named abstraction to concrete lazily in singleton mode. The concrete is resolved only when the abstraction is resolved for the first time.
func (Container) NamedTransient ¶ added in v3.1.4
NamedTransient binds a named abstraction to concrete lazily in transient mode.
func (Container) NamedTransientLazy ¶ added in v3.3.0
NamedTransient binds a named abstraction to concrete in transient mode. Normally the resolver will be called during registration, but that is skipped in lazy mode.
func (Container) Reset ¶ added in v3.1.4
func (c Container) Reset()
Reset deletes all the existing bindings and empties the container.
func (Container) Resolve ¶ added in v3.1.4
Resolve takes an abstraction (reference of an interface type) and fills it with the related concrete.
func (Container) Singleton ¶ added in v3.1.4
Singleton binds an abstraction to concrete in singleton mode. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.
func (Container) SingletonLazy ¶ added in v3.3.0
SingletonLazy binds an abstraction to concrete lazily in singleton mode. The concrete is resolved only when the abstraction is resolved for the first time. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.
func (Container) Transient ¶ added in v3.1.4
Transient binds an abstraction to concrete in transient mode. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.
func (Container) TransientLazy ¶ added in v3.3.0
TransientLazy binds an abstraction to concrete lazily in transient mode. Normally the resolver will be called during registration, but that is skipped in lazy mode. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Container already.