Documentation
¶
Index ¶
- type ConstructorFn
- type Service
- func (s *Service) Add(name string, thing interface{})
- func (s *Service) AddClass(name string, ctor ConstructorFn)
- func (s *Service) Classes() []string
- func (s *Service) CountClasses() int
- func (s *Service) CountServices() int
- func (s *Service) CreateNew(name string) (interface{}, bool)
- func (s *Service) Get(name string) (interface{}, bool)
- func (s *Service) Services() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstructorFn ¶ added in v0.4.1
type ConstructorFn func() interface{}
Constructor function for creating new service records.
type Service ¶
Service structure.
To use:
1) Invoke `service.GetInstance` to access the singleton:
```go
svc := service.GetInstance
```
2a) Add your required service:
```go
svc.Add("SomeName", someInstance)
```
2b) Create your required service:
```go
svc.Create("SomeName", func() interface{} { return NewThing() })
```
Profit.
func (*Service) AddClass ¶
func (s *Service) AddClass(name string, ctor ConstructorFn)
Add a new class with the given name.
func (*Service) CountClasses ¶
Return a count of registered classes.
func (*Service) CountServices ¶
Return a count of registered services.
func (*Service) CreateNew ¶
Create a new instance of the given class by invoking its registered constructor.
Click to show internal directories.
Click to hide internal directories.