Central container for managing dependencies and performing dependency injection.
Mote: Container use Caster for get dependencies by type.
import "github.com/gomig/container";
cnt := container.NewContainer();
Container interface contains following methods:
Add new dependency to container
// Signature:
Register(name string, dep any)
// Example:
cnt.Register("app-name", "My App")
Get dependency. this function return false as second return value if dependency not exists.
Caution: Resolve return data as any
type. if you need to parse data as special type use helper parser methods described later.
// Signature:
Resolve(name string) (any, bool)
// Example:
appName, exists := cnt.Resolve("app-name") // => "My App", true
Check if dependency exists.
// Signature:
Exists(name string) bool
// Example:
exists := cnt.Exists("app-name") // => true
Parse dependency as caster.
// Signature:
Cast(name string) caster.Caster
// Example:
v, err := cnt.Cast("timeout").Int()