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 DeepFill(receiver interface{}, dependencies *interface{}) error
- func Fill(receiver interface{}) error
- func MustCall(c Container, receiver interface{})
- func MustDeepFill(c Container, receiver interface{}, dependencies 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) DeepFill(structure interface{}, dependencies 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 ¶
func MustCall(c Container, receiver interface{})
MustCall wraps the `Call` method and panics on errors instead of returning the errors.
func MustDeepFill ¶
func MustDeepFill(c Container, receiver interface{}, dependencies interface{})
MustDeepFill wraps the `Fill` method and panics on errors instead of returning the errors.
func MustFill ¶
func MustFill(c Container, receiver interface{})
MustFill wraps the `Fill` method and panics on errors instead of returning the errors.
func MustNamedResolve ¶
MustNamedResolve wraps the `NamedResolve` method and panics on errors instead of returning the errors.
func MustNamedSingleton ¶
MustNamedSingleton wraps the `NamedSingleton` method and panics on errors instead of returning the errors.
func MustNamedSingletonLazy ¶
MustNamedSingleton wraps the `NamedSingletonLazy` method and panics on errors instead of returning the errors.
func MustNamedTransient ¶
MustNamedTransient wraps the `NamedTransient` method and panics on errors instead of returning the errors.
func MustNamedTransientLazy ¶
MustNamedTransient wraps the `NamedTransientLazy` method and panics on errors instead of returning the errors.
func MustResolve ¶
func MustResolve(c Container, abstraction interface{})
MustResolve wraps the `Resolve` method and panics on errors instead of returning the errors.
func MustSingleton ¶
func MustSingleton(c Container, resolver interface{})
MustSingleton wraps the `Singleton` method and panics on errors instead of returning the errors.
func MustSingletonLazy ¶
func MustSingletonLazy(c Container, resolver interface{})
MustSingleton wraps the `SingletonLazy` method and panics on errors instead of returning the errors.
func MustTransient ¶
func MustTransient(c Container, resolver interface{})
MustTransient wraps the `Transient` method and panics on errors instead of returning the errors.
func MustTransientLazy ¶
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 ¶
NamedSingletonLazy calls the same method of the global concrete.
func NamedTransient ¶
NamedTransient calls the same method of the global concrete.
func NamedTransientLazy ¶
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 ¶
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 ¶
func TransientLazy(resolver interface{}) error
TransientLazy calls the same method of the global concrete.
Types ¶
type Container ¶
Container holds the bindings and provides methods to interact with them. It is the entry point in the package.
func (Container) Call ¶
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) DeepFill ¶
DeepFill recursively injects dependencies into the target struct. You can also provide additional direct dependencies as a second argument (a struct pointer). The container will prioritize injecting the provided direct dependencies over those in the container. This is useful for passing temporary dependencies, such as (w, *r, session).
func (Container) Fill ¶
Fill takes a struct and resolves the fields with the tag `container:"inject"`
func (Container) NamedResolve ¶
NamedResolve takes abstraction and its name and fills it with the related concrete.
func (Container) NamedSingleton ¶
NamedSingleton binds a named abstraction to concrete in singleton mode.
func (Container) NamedSingletonLazy ¶
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 ¶
NamedTransient binds a named abstraction to concrete lazily in transient mode.
func (Container) NamedTransientLazy ¶
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 ¶
func (c Container) Reset()
Reset deletes all the existing bindings and empties the container.
func (Container) Resolve ¶
Resolve takes an abstraction (reference of an interface type) and fills it with the related concrete.
func (Container) Singleton ¶
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 ¶
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 ¶
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 ¶
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.