Documentation
¶
Index ¶
- type Context
- func (c *Context) Close(item interface{})
- func (c *Context) ContextManager() *ContextManager
- func (c *Context) Delete()
- func (c *Context) Fill(item interface{}, name string, params ...interface{}) error
- func (c *Context) HasSubScope(scope string) bool
- func (c *Context) Make(name string, params ...interface{}) interface{}
- func (c *Context) Parent() *Context
- func (c *Context) ParentScopes() []string
- func (c *Context) ParentWithScope(scope string) *Context
- func (c *Context) SafeMake(name string, params ...interface{}) (interface{}, error)
- func (c *Context) Scope() string
- func (c *Context) SubContext(scope string) (*Context, error)
- func (c *Context) SubScopes() []string
- type ContextManager
- type Instance
- type Maker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context can build items thanks to their definition contained in a ContextManager.
func (*Context) Close ¶
func (c *Context) Close(item interface{})
Close apply the Close method defined in a Maker on an item build with the Make method of the Maker and retrived with the Make method of this Context.
func (*Context) ContextManager ¶
func (c *Context) ContextManager() *ContextManager
ContextManager returns the ContextManager that has generated this Context.
func (*Context) Delete ¶
func (c *Context) Delete()
Delete removes all the references to the items that has been made by this context. Before removing the references, it calls the Close method on these items. It will also call Delete on every child and remove its reference in the parent Context.
func (*Context) HasSubScope ¶
HasSubScope returns true if scope is one of this context subscopes.
func (*Context) ParentScopes ¶
ParentScopes returns the list of this context parent scopes.
func (*Context) ParentWithScope ¶
ParentWithScope looks over the parents to find one with the given scope.
func (*Context) SafeMake ¶
SafeMake creates a new item. If the item can't be created, it returns an error.
func (*Context) SubContext ¶
SubContext creates a new Context in a subscope that will have this Container as parent.
type ContextManager ¶
type ContextManager struct {
// contains filtered or unexported fields
}
ContextManager contains the definition of every items. You must use the NewContextManager function to create a ContextManager.
func NewContextManager ¶
func NewContextManager(scopes ...string) (*ContextManager, error)
NewContextManager creates a new ContextManager initialized with a list of scopes. If a > b then scope[a] is a sub-scope of scope[b]. For example if scopes are ["app", "request"], then "request" is a sub-scope of "app".
func (*ContextManager) Context ¶
func (cm *ContextManager) Context(scope string) (*Context, error)
Context returns a context for the desired scope. You can ask for any scope, not only the first one. But if you have two scopes ["app", "request"] and you ask for a "request" Context twice, it will create two different "app" Context.
func (*ContextManager) Instance ¶
func (cm *ContextManager) Instance(instance Instance) error
Instance adds an Instance to the ContextManager. It returns an error if the name or the aliases are already used.
func (*ContextManager) Maker ¶
func (cm *ContextManager) Maker(maker Maker) error
Maker adds a Maker to the ContextManager. It returns an error if the Maker is not well defined.
func (*ContextManager) NameIsUsed ¶
func (cm *ContextManager) NameIsUsed(name string) bool
NameIsUsed returns true if the name is already used in the ContextManager. It can be used as an Instance name, a Maker name, or as an alias.
func (*ContextManager) ResolveName ¶
func (cm *ContextManager) ResolveName(name string) (string, error)
ResolveName returns the real name of an entry by fowling aliases. If the name is not used, it returns an empty string and an error.