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 MustNamedTransient(c Container, name string, resolver interface{})
- func MustResolve(c Container, abstraction interface{})
- func MustSingleton(c Container, resolver interface{})
- func MustTransient(c Container, resolver interface{})
- func NamedResolve(abstraction interface{}, name string) error
- func NamedSingleton(name string, resolver interface{}) error
- func NamedTransient(name string, resolver interface{}) error
- func Reset()
- func Resolve(abstraction interface{}) error
- func Singleton(resolver interface{}) error
- func Transient(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) NamedTransient(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) Transient(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 MustNamedTransient ¶ added in v3.2.0
MustNamedTransient wraps the `NamedTransient` 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 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 NamedResolve ¶
NamedResolve calls the same method of the global concrete.
func NamedSingleton ¶
NamedSingleton calls the same method of the global concrete.
func NamedTransient ¶
NamedTransient calls the same method of the global concrete.
func Resolve ¶
func Resolve(abstraction interface{}) error
Resolve 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) NamedTransient ¶ added in v3.1.4
NamedTransient binds a named abstraction to concrete in transient 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) 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.