di

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(dest interface{}, module Module) error

Init retrieves an instance of the dest from the container.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

func (*Container) Import

func (c *Container) Import(module Module)

Import can be used to combine multiple modules into one.

func (*Container) Register

func (c *Container) Register(provider interface{}, as ...interface{})

Register teaches container how to create an instance of the given type, for instance:

container.Register(
    // tell the container how to create an instance of *MyType
    func() *MyType { return &MyType{} },
)

container.Register(
    // tell the container how to create an instance of *MyOtherType from *MyType
    func(*MyType) *MyOtherType { ... },
    // second argument registers *MyOtherType as MyOtherTypeInterface too.
    new(MyOtherTypeInterface),
)

Register also registers resolvers for pointers to the type, so circular dependencies are possible:

container.Register(func(*MyOtherType) MyType { ... })
container.Register(func(*MyType) MyOtherTypeType { ... })

type Module

type Module func(*Container)

type Out

type Out = dig.Out

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL