Documentation
¶
Overview ¶
Package ioc provides an IoC container for Go projects. It provides simple, fluent and easy-to-use interface to make dependency injection in GoLang easier.
Index ¶
- type Container
- func (c *Container) Call(function interface{}, returnedValues ...interface{})
- func (c *Container) ForEachNamed(function interface{})
- func (c *Container) Names(example interface{}) []string
- func (c *Container) Reset()
- func (c *Container) Resolve(receiver interface{})
- func (c *Container) ResolveNamed(name string, receiver interface{})
- func (c *Container) Singleton(resolver interface{})
- func (c *Container) SingletonNamed(name string, resolver interface{})
- func (c *Container) SubContainer() *Container
- func (c *Container) Transient(resolver interface{})
- func (c *Container) TransientNamed(name string, resolver interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a IoC container
func (*Container) Call ¶
func (c *Container) Call(function interface{}, returnedValues ...interface{})
Call will call the given function and return its returned values.
func (*Container) ForEachNamed ¶
func (c *Container) ForEachNamed(function interface{})
ForEachNamed iterates over all named concretes
func (*Container) Reset ¶
func (c *Container) Reset()
Reset will reset the container and remove all the bindings.
func (*Container) Resolve ¶
func (c *Container) Resolve(receiver interface{})
Resolve will resolve the dependency and return an appropriate concrete of the given abstraction. It can take an abstraction (interface reference) and fill it with the related implementation. It also can takes a function (receiver) with one or more arguments of the abstractions (interfaces) that need to be resolved, Container will invoke the receiver function and pass the related implementations.
func (*Container) ResolveNamed ¶
ResolveNamed will resolve the named dependency and return an appropriate concrete of the given abstraction. It can take an abstraction (interface reference) and fill it with the related implementation. It also can takes a function (receiver) with one or more arguments of the abstractions (interfaces) that need to be resolved, Container will invoke the receiver function and pass the related implementations.
func (*Container) Singleton ¶
func (c *Container) Singleton(resolver interface{})
Singleton will bind an abstraction to a concrete for further singleton resolves. It takes a resolver function which returns the concrete and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have bound already in Container.
func (*Container) SingletonNamed ¶
SingletonNamed will bind a named abstraction to a concrete for further singleton resolves. It takes a resolver function which returns the concrete and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have bound already in Container.
func (*Container) SubContainer ¶
SubContainer creates sub container Bindings are resolved in sub container first and if it's not possible request is redirected to the parent one
func (*Container) Transient ¶
func (c *Container) Transient(resolver interface{})
Transient will bind an abstraction to a concrete for further transient resolves. It takes a resolver function which returns the concrete and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have bound already in Container.
func (*Container) TransientNamed ¶
TransientNamed will bind a named abstraction to a concrete for further transient resolves. It takes a resolver function which returns the concrete and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have bound already in Container.