Documentation
¶
Index ¶
- Constants
- Variables
- type Application
- type ServiceContainer
- func (c ServiceContainer) Clear() error
- func (c ServiceContainer) Close() error
- func (c ServiceContainer) Factory(id string, factory ServiceFactory, tags ...string) error
- func (c ServiceContainer) Get(id string) (any, error)
- func (c ServiceContainer) Has(id string) bool
- func (c ServiceContainer) Remove(id string) error
- func (c ServiceContainer) Service(id string, factory ServiceFactory, tags ...string) error
- func (c ServiceContainer) Tagged(tag string) ([]any, error)
- type ServiceFactory
- type ServiceProvider
Constants ¶
const (
// ContainerID defines the gapp package container id base string.
ContainerID = "gapp"
)
const (
// EnvBase defines the gapp package environment base string.
EnvBase = "GAPP"
)
Variables ¶
var ( // ErrNilPointer defines a nil pointer argument error ErrNilPointer = errors.New("invalid nil pointer") // ErrConversion defines a type conversion error ErrConversion = errors.New("invalid type conversion") // ErrServiceNotFound defines a service not found on the container ErrServiceNotFound = errors.New("service not found") )
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
Container ServiceContainer
// contains filtered or unexported fields
}
Application defines the structure that controls the application container and container initialization.
func NewApplication ¶
func NewApplication() *Application
NewApplication used to instantiate a new application.
func (*Application) Add ¶
func (a *Application) Add(id string, provider ServiceProvider) error
Add will register a new provider into the application used on the application boot.
func (*Application) Boot ¶
func (a *Application) Boot() (err error)
Boot initializes the application if not initialized yet. The initialization of an application is the calling of the register method on all providers, after the registration of all objects in the container, the boot method of all providers will be executed.
type ServiceContainer ¶ added in v1.20.0
type ServiceContainer map[string]serviceContainerEntry
ServiceContainer defines the structure that hold the application service factories and initialized services.
func (ServiceContainer) Clear ¶ added in v1.20.0
func (c ServiceContainer) Clear() error
Clear will eliminate all the registered object from the container.
func (ServiceContainer) Close ¶ added in v1.20.0
func (c ServiceContainer) Close() error
Close clean up the container from all the stored objects. If the object has been already instantiated and implements the Closable interface, then the Close method will be called upon the removing instance.
func (ServiceContainer) Factory ¶ added in v1.20.0
func (c ServiceContainer) Factory(id string, factory ServiceFactory, tags ...string) error
Factory will register a service factory used to return a new instance every time you request it. If any object was registered previously with the requested id, then the object will be removed by calling the Remove method previously the storing of the new object factory.
func (ServiceContainer) Get ¶ added in v1.20.0
func (c ServiceContainer) Get(id string) (any, error)
Get will retrieve the requested object from the container. If the object has not yet been instantiated, then the factory method will be executed to instantiate it.
func (ServiceContainer) Has ¶ added in v1.20.0
func (c ServiceContainer) Has(id string) bool
Has will check if an object is registered with the requested id. This does not mean that is instantiated. The instantiation is just executed when the instance is requested for the first time.
func (ServiceContainer) Remove ¶ added in v1.20.0
func (c ServiceContainer) Remove(id string) error
Remove will eliminate the object from the container. If the object has been already instantiated and implements the Closable interface, then the Close method will be called on the removing instance.
func (ServiceContainer) Service ¶ added in v1.20.0
func (c ServiceContainer) Service(id string, factory ServiceFactory, tags ...string) error
Service will register a service factory used to return an instance generated by the given factory. This factory method will only be called once, meaning that everytime the service is requested, is always returned the same instance. If any object was registered previously with the requested id, then the object will be removed by calling the Remove method previously the storing of the new object factory.
type ServiceFactory ¶ added in v1.20.0
ServiceFactory is a callback function used to instantiate an object used by the application container when a not yet instantiated object is requested.
type ServiceProvider ¶ added in v1.20.0
type ServiceProvider interface {
Register(ServiceContainer) error
Boot(ServiceContainer) error
}
ServiceProvider is an interface used to define the methods of an object that can be registered into a gapp application and register elements in the application container and do some necessary boot actions on initialization.