Documentation ¶
Index ¶
- Variables
- type ApplicationContainer
- func (c *ApplicationContainer) Invoke(name string) (interface{}, error)
- func (c *ApplicationContainer) InvokeByType(obj interface{}) (interface{}, error)
- func (c *ApplicationContainer) InvokeByTypeP(obj interface{}) interface{}
- func (c *ApplicationContainer) InvokeP(name string) interface{}
- func (c *ApplicationContainer) Logger() *slog.Logger
- func (c *ApplicationContainer) Register(name string, obj interface{}) error
- func (c *ApplicationContainer) Run()
- func (c *ApplicationContainer) WithProvider(provider IProvider) *ApplicationContainer
- type BaseProvider
- type ContainerLogsOpts
- type ContainerOpts
- type DependencyGraph
- func (g *DependencyGraph) AddEdge(v, w string) error
- func (g *DependencyGraph) AddVertex(v string)
- func (g *DependencyGraph) IsCyclic() bool
- func (g *DependencyGraph) TopologicalSort() ([]string, error)
- func (g *DependencyGraph) TopologicalSortDFS() ([]string, error)
- func (g *DependencyGraph) TopologicalSortKahn() ([]string, error)
- type IApp
- type IContainer
- type IContainerMonitor
- type IProvider
- type RegisteredProvider
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDependencyNotProvided dependency has not been provided ErrDependencyNotProvided = errors.New("dependency has not been provided") // ErrNilDependency the provided dependency cannot be nil ErrNilDependency = errors.New("the provided dependency cannot be nil") // ErrDependencyAlreadyProvided dependency already provided ErrDependencyAlreadyProvided = errors.New("dependency already provided") )
Functions ¶
This section is empty.
Types ¶
type ApplicationContainer ¶
type ApplicationContainer struct {
// contains filtered or unexported fields
}
ApplicationContainer implementation of the IApp interface. Handles the app life cycle and the main dependency container.
func NewApplicationContainer ¶ added in v0.3.7
func NewApplicationContainer(opts ContainerOpts) *ApplicationContainer
NewApplicationContainer app container constructor
func NewContainer ¶
func NewContainer(opts ContainerOpts) *ApplicationContainer
NewContainer app container constructor
func (*ApplicationContainer) Invoke ¶
func (c *ApplicationContainer) Invoke(name string) (interface{}, error)
Invoke fetch a named dependency from the container or error if not exists.
func (*ApplicationContainer) InvokeByType ¶
func (c *ApplicationContainer) InvokeByType(obj interface{}) (interface{}, error)
InvokeByType fetch an object registered by type or error if not exists.
func (*ApplicationContainer) InvokeByTypeP ¶
func (c *ApplicationContainer) InvokeByTypeP(obj interface{}) interface{}
InvokeByTypeP fetch an object registered by type or panic if not exists.
func (*ApplicationContainer) InvokeP ¶
func (c *ApplicationContainer) InvokeP(name string) interface{}
InvokeP fetch a named dependency from the container and panic if not exists.
func (*ApplicationContainer) Logger ¶
func (c *ApplicationContainer) Logger() *slog.Logger
Logger returns the container logger useful to log something into your providers
func (*ApplicationContainer) Register ¶
func (c *ApplicationContainer) Register(name string, obj interface{}) error
Register exposed method to register object by name without linked hooks
func (*ApplicationContainer) Run ¶
func (c *ApplicationContainer) Run()
Run app method to starts the application life cycle
func (*ApplicationContainer) WithProvider ¶
func (c *ApplicationContainer) WithProvider(provider IProvider) *ApplicationContainer
WithProvider provides dependencies
type BaseProvider ¶
type BaseProvider struct{}
BaseProvider no operation provider to create your own provider
func (*BaseProvider) OnStart ¶
func (p *BaseProvider) OnStart() func() error
OnStart returns a hook function to be executed at start step
func (*BaseProvider) OnStop ¶
func (p *BaseProvider) OnStop() func() error
OnStop returns a hook function to be executed at stop step
type ContainerLogsOpts ¶
ContainerLogsOpts struct to configure the container log
type ContainerOpts ¶
type ContainerOpts struct {
Log ContainerLogsOpts
}
ContainerOpts application container options
type DependencyGraph ¶ added in v0.5.0
type DependencyGraph struct {
// contains filtered or unexported fields
}
DependencyGraph graph to validate injected dependencies
func NewDependencyGraph ¶ added in v0.5.0
func NewDependencyGraph() *DependencyGraph
NewDependencyGraph constructor of DependencyGraph
func (*DependencyGraph) AddEdge ¶ added in v0.5.0
func (g *DependencyGraph) AddEdge(v, w string) error
AddEdge adds edge from v to w
func (*DependencyGraph) AddVertex ¶ added in v0.5.0
func (g *DependencyGraph) AddVertex(v string)
AddVertex adds a vertex to the graph
func (*DependencyGraph) IsCyclic ¶ added in v0.5.0
func (g *DependencyGraph) IsCyclic() bool
IsCyclic validates if the constructed graph has at least one cycle built on top of DFS topological sort.
func (*DependencyGraph) TopologicalSort ¶ added in v0.5.0
func (g *DependencyGraph) TopologicalSort() ([]string, error)
TopologicalSort by default calls a DFS based algorithm
func (*DependencyGraph) TopologicalSortDFS ¶ added in v0.5.0
func (g *DependencyGraph) TopologicalSortDFS() ([]string, error)
TopologicalSortDFS based on Depth-first search
func (*DependencyGraph) TopologicalSortKahn ¶ added in v0.5.0
func (g *DependencyGraph) TopologicalSortKahn() ([]string, error)
TopologicalSortKahn based on Kahn's algorithm
IMPORTANT:
This implementation removes edges from original graph, so, once that has been executed the original graph will be modified.
TODO: clone graph before execution.
type IApp ¶
type IApp interface { IContainer Run() // contains filtered or unexported methods }
IApp application interface
type IContainer ¶
type IContainer interface { IContainerMonitor Register(name string, obj interface{}) error Invoke(name string) (interface{}, error) InvokeP(name string) interface{} InvokeByType(obj interface{}) (interface{}, error) InvokeByTypeP(obj interface{}) interface{} }
IContainer exposed interface that defines the container methods
type IContainerMonitor ¶
IContainerMonitor interface that defines the container monitoring capabilities
type IProvider ¶
type IProvider interface { Provide(c IContainer) error OnStart() func() error OnStop() func() error }
IProvider dependency provider interface that cover the app life-cycle events
type RegisteredProvider ¶ added in v0.5.0
type RegisteredProvider struct {
// contains filtered or unexported fields
}