Documentation
¶
Index ¶
- func ExecAllByLabel(c Container, label Label) ([][]any, error)
- func ExecAllByType[T any](c Container) ([][]any, error)
- func ExecByLabel(c Container, label Label) ([]any, error)
- func ExecByRef(c Container, ref FuncReference) ([]any, error)
- func ExecByType[T any](c Container) ([]any, error)
- func SetDefaultAutowired()
- func SetDefaultEager()
- func SetDefaultLazy()
- func SetDefaultNotAutowired()
- func SetDefaultNotShared()
- func SetDefaultShared()
- func SvcByLabel[T any](c Container, label Label) (T, error)
- func SvcByRef[T any](c Container, ref SvcReference) (T, error)
- func SvcByType[T any](c Container) (T, error)
- func SvcsByLabel[T any](c Container, label Label) ([]T, error)
- func SvcsByType[T any](c Container) ([]T, error)
- type ArgBuilder
- type Builder
- func (b *Builder) Bindings(bindings ...*InterfaceBindingBuilder) *Builder
- func (b *Builder) Build() (Container, error)
- func (b *Builder) CompilerPasses(passes ...*di.CompilerPass) *Builder
- func (b *Builder) Functions(functions ...*FunctionDefinitionBuilder) *Builder
- func (b *Builder) Services(services ...*ServiceDefinitionBuilder) *Builder
- type BuilderOption
- type Container
- type FuncReference
- type FunctionDefinitionBuilder
- func (b *FunctionDefinitionBuilder) Autowired() *FunctionDefinitionBuilder
- func (b *FunctionDefinitionBuilder) Bind(ref *FuncReference) *FunctionDefinitionBuilder
- func (b *FunctionDefinitionBuilder) Build(scope *di.Scope) (joinedErrs error)
- func (b *FunctionDefinitionBuilder) Children(services ...*ServiceDefinitionBuilder) *FunctionDefinitionBuilder
- func (b *FunctionDefinitionBuilder) Eager() *FunctionDefinitionBuilder
- func (b *FunctionDefinitionBuilder) Labels(labels ...Label) *FunctionDefinitionBuilder
- func (b *FunctionDefinitionBuilder) Lazy() *FunctionDefinitionBuilder
- func (b *FunctionDefinitionBuilder) NotAutowired() *FunctionDefinitionBuilder
- type ID
- type InterfaceBindingBuilder
- type Label
- type ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) Autowired() *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) Bind(ref *SvcReference) *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) Build(scope *di.Scope) (joinedErrs error)
- func (b *ServiceDefinitionBuilder) Children(services ...*ServiceDefinitionBuilder) *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) Eager() *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) Labels(labels ...Label) *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) Lazy() *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) MethodCall(method any, args ...any) *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) NotAutowired() *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) NotShared() *ServiceDefinitionBuilder
- func (b *ServiceDefinitionBuilder) ParseAndBuild(scope *di.Scope) error
- func (b *ServiceDefinitionBuilder) ParseFactory() (joinedErrs error)
- func (b *ServiceDefinitionBuilder) Shared() *ServiceDefinitionBuilder
- type SvcReference
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecAllByLabel ¶
ExecAllByLabel executes all function by their type.
func ExecAllByType ¶
ExecAllByType executes all function by their type.
func ExecByLabel ¶
ExecByLabel executes a function by its label.
func ExecByRef ¶
func ExecByRef(c Container, ref FuncReference) ([]any, error)
ExecByRef executes a function by its reference.
func ExecByType ¶
ExecByType executes a function by its type.
func SetDefaultAutowired ¶
func SetDefaultAutowired()
func SetDefaultEager ¶
func SetDefaultEager()
func SetDefaultLazy ¶
func SetDefaultLazy()
func SetDefaultNotAutowired ¶
func SetDefaultNotAutowired()
func SetDefaultNotShared ¶
func SetDefaultNotShared()
func SetDefaultShared ¶
func SetDefaultShared()
func SvcByLabel ¶
SvcByLabel returns a service from the container by its label.
func SvcByRef ¶
func SvcByRef[T any](c Container, ref SvcReference) (T, error)
SvcByRef returns a service from the container by its reference.
func SvcsByLabel ¶
SvcsByLabel returns all services from the container by their label.
func SvcsByType ¶
SvcsByType returns all services from the container by their type.
Types ¶
type ArgBuilder ¶
type ArgBuilder struct {
// contains filtered or unexported fields
}
ArgBuilder is a helper for building arguments. It is used by the DefinitionBuilder to define arguments for a service factory and method calls.
func Arg ¶
func Arg(v any) *ArgBuilder
Arg returns an argument builder appropriate for the given value.
func Compound ¶
func Compound[T any](builders ...*ArgBuilder) *ArgBuilder
Compound returns an argument builder for an argument composed of other arguments.
func Ref ¶
func Ref(ref *SvcReference) *ArgBuilder
Ref returns an argument builder for a service reference.
func SliceOf ¶
func SliceOf[T any](label ...Label) *ArgBuilder
SliceOf returns an argument builder for a typed reference to a slice.
func Type ¶
func Type[T any](label ...Label) *ArgBuilder
Type returns an argument builder for a typed reference.
func (*ArgBuilder) Slot ¶
func (b *ArgBuilder) Slot(n uint) *ArgBuilder
Slot sets the slot of the argument. E.g. Slot(1) will set the argument as the second argument of a function.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a helper for building a container. It offers a fluent interface that incorporates other helpers to make the process of setting up the container easy and convenient for the user. This is the recommended way of building a container.
func New ¶
func New(opts ...BuilderOption) *Builder
New creates a new Builder. This is the recommended entrypoint to the godi library.
func (*Builder) Bindings ¶
func (b *Builder) Bindings(bindings ...*InterfaceBindingBuilder) *Builder
func (*Builder) CompilerPasses ¶
func (b *Builder) CompilerPasses(passes ...*di.CompilerPass) *Builder
func (*Builder) Functions ¶
func (b *Builder) Functions(functions ...*FunctionDefinitionBuilder) *Builder
func (*Builder) Services ¶
func (b *Builder) Services(services ...*ServiceDefinitionBuilder) *Builder
type BuilderOption ¶
func SkipCycleValidation ¶
func SkipCycleValidation() BuilderOption
type Container ¶
type Container interface {
HasService(id di.ID) bool
GetService(id di.ID) (any, error)
GetServices(ids ...di.ID) (svcs []any, err error)
GetServicesIDsByType(typ reflect.Type) []ID
GetServicesByType(typ reflect.Type) ([]any, error)
GetServicesIDsByLabel(label Label) []ID
GetServicesByLabel(label di.Label) ([]any, error)
HasFunction(id di.ID) bool
ExecuteFunction(id di.ID) ([]any, error)
ExecuteFunctions(ids ...di.ID) (results [][]any, err error)
GetFunctionsIDsByType(typ reflect.Type) []ID
ExecuteFunctionsByType(typ reflect.Type) ([][]any, error)
GetFunctionsIDsByLabel(label Label) []ID
ExecuteFunctionsByLabel(label di.Label) ([][]any, error)
Print(w io.Writer)
}
type FuncReference ¶
type FuncReference struct {
// contains filtered or unexported fields
}
func (FuncReference) FuncID ¶
func (r FuncReference) FuncID() ID
func (FuncReference) IsEmpty ¶
func (r FuncReference) IsEmpty() bool
func (FuncReference) String ¶
func (r FuncReference) String() string
type FunctionDefinitionBuilder ¶
type FunctionDefinitionBuilder struct {
// contains filtered or unexported fields
}
FunctionDefinitionBuilder is a helper for building di.FunctionDefinition objects. It offers a fluent interface that does all the heavy lifting for the user. This is the recommended way of building a di.FunctionDefinition.
func Func ¶
func Func(fn any, args ...any) *FunctionDefinitionBuilder
Func creates a new FunctionDefinitionBuilder.
func (*FunctionDefinitionBuilder) Autowired ¶
func (b *FunctionDefinitionBuilder) Autowired() *FunctionDefinitionBuilder
func (*FunctionDefinitionBuilder) Bind ¶
func (b *FunctionDefinitionBuilder) Bind(ref *FuncReference) *FunctionDefinitionBuilder
func (*FunctionDefinitionBuilder) Build ¶
func (b *FunctionDefinitionBuilder) Build(scope *di.Scope) (joinedErrs error)
func (*FunctionDefinitionBuilder) Children ¶
func (b *FunctionDefinitionBuilder) Children(services ...*ServiceDefinitionBuilder) *FunctionDefinitionBuilder
func (*FunctionDefinitionBuilder) Eager ¶
func (b *FunctionDefinitionBuilder) Eager() *FunctionDefinitionBuilder
func (*FunctionDefinitionBuilder) Labels ¶
func (b *FunctionDefinitionBuilder) Labels(labels ...Label) *FunctionDefinitionBuilder
func (*FunctionDefinitionBuilder) Lazy ¶
func (b *FunctionDefinitionBuilder) Lazy() *FunctionDefinitionBuilder
func (*FunctionDefinitionBuilder) NotAutowired ¶
func (b *FunctionDefinitionBuilder) NotAutowired() *FunctionDefinitionBuilder
type InterfaceBindingBuilder ¶
type InterfaceBindingBuilder struct {
// contains filtered or unexported fields
}
func BindArg ¶
func BindArg[Iface any](bindTo *ArgBuilder) *InterfaceBindingBuilder
BindArg binds the interface Iface to the given argument (bindTo).
func BindSlice ¶
func BindSlice[Iface, To any]() *InterfaceBindingBuilder
BindSlice binds the interface Iface, or []Iface, to a slice []To.
func BindType ¶
func BindType[Iface, To any]() *InterfaceBindingBuilder
BindType binds the interface Iface to the type To.
type ServiceDefinitionBuilder ¶
type ServiceDefinitionBuilder struct {
// contains filtered or unexported fields
}
ServiceDefinitionBuilder is a helper for building di.ServiceDefinition objects. It offers a fluent interface that does all the heavy lifting for the user. This is the recommended way of building a di.ServiceDefinition.
func Svc ¶
func Svc(factory any, args ...any) *ServiceDefinitionBuilder
Svc creates a new ServiceDefinitionBuilder.
func SvcVal ¶
func SvcVal[T any](svc T) *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) Autowired ¶
func (b *ServiceDefinitionBuilder) Autowired() *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) Bind ¶
func (b *ServiceDefinitionBuilder) Bind(ref *SvcReference) *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) Build ¶
func (b *ServiceDefinitionBuilder) Build(scope *di.Scope) (joinedErrs error)
func (*ServiceDefinitionBuilder) Children ¶
func (b *ServiceDefinitionBuilder) Children(services ...*ServiceDefinitionBuilder) *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) Eager ¶
func (b *ServiceDefinitionBuilder) Eager() *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) Labels ¶
func (b *ServiceDefinitionBuilder) Labels(labels ...Label) *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) Lazy ¶
func (b *ServiceDefinitionBuilder) Lazy() *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) MethodCall ¶
func (b *ServiceDefinitionBuilder) MethodCall(method any, args ...any) *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) NotAutowired ¶
func (b *ServiceDefinitionBuilder) NotAutowired() *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) NotShared ¶
func (b *ServiceDefinitionBuilder) NotShared() *ServiceDefinitionBuilder
func (*ServiceDefinitionBuilder) ParseAndBuild ¶
func (b *ServiceDefinitionBuilder) ParseAndBuild(scope *di.Scope) error
func (*ServiceDefinitionBuilder) ParseFactory ¶
func (b *ServiceDefinitionBuilder) ParseFactory() (joinedErrs error)
ParseFactory parses the factory function WITHOUT the arguments to determine the service type. This method MUST be called prior to build.
func (*ServiceDefinitionBuilder) Shared ¶
func (b *ServiceDefinitionBuilder) Shared() *ServiceDefinitionBuilder
type SvcReference ¶
type SvcReference struct {
// contains filtered or unexported fields
}
func (SvcReference) IsEmpty ¶
func (r SvcReference) IsEmpty() bool
func (SvcReference) String ¶
func (r SvcReference) String() string
func (SvcReference) SvcID ¶
func (r SvcReference) SvcID() ID