Documentation ¶
Index ¶
- Constants
- type Application
- type IApplication
- type IServiceContainer
- type IServiceFactory
- type IServiceProvider
- type ServiceContainer
- func (c ServiceContainer) Clear() error
- func (c ServiceContainer) Close() error
- func (c ServiceContainer) Factory(id string, factory IServiceFactory, 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 IServiceFactory, tags ...string) error
- func (c ServiceContainer) Tagged(tag string) ([]any, error)
Constants ¶
const (
// ContainerID defines the slate package container id base string.
ContainerID = "slate"
)
const (
// EnvID defines the slate package base environment variable name.
EnvID = "SLATE"
)
Variables ¶
This section is empty.
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(provider IServiceProvider) error
Add will register a new provider into the application used on the application boot.
func (*Application) Boot ¶
func (a *Application) Boot() (e 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 IApplication ¶ added in v0.9.0
type IApplication interface { Add(provider IServiceProvider) error Boot() error }
IApplication defines the interface of a slate application instance.
type IServiceContainer ¶ added in v0.9.0
type IServiceContainer interface { io.Closer Has(id string) bool Remove(id string) error Clear() error Service(id string, factory IServiceFactory, tags ...string) error Factory(id string, factory IServiceFactory, tags ...string) error Get(id string) (any, error) Tagged(tag string) ([]any, error) }
IServiceContainer defines the interface of a slate application service container instance.
type IServiceFactory ¶ added in v0.10.0
IServiceFactory is a callback function used to instantiate an object used by the application container when a not yet instantiated object is requested.
type IServiceProvider ¶ added in v0.9.0
type IServiceProvider interface { Register(ServiceContainer) error Boot(ServiceContainer) error }
IServiceProvider is an interface used to define the methods of an object that can be registered into a slate application and register elements in the application container and do some necessary boot actions on initialization.
type ServiceContainer ¶
type ServiceContainer map[string]serviceContainerEntry
ServiceContainer defines the structure that hold the application service factories and initialized services.
func (ServiceContainer) Clear ¶
func (c ServiceContainer) Clear() error
Clear will eliminate all the registered object from the container.
func (ServiceContainer) Close ¶
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 ¶
func (c ServiceContainer) Factory(id string, factory IServiceFactory, 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 ¶
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 ¶
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 ¶
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 ¶
func (c ServiceContainer) Service(id string, factory IServiceFactory, 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.