Documentation ¶
Index ¶
- type CircularDependencyError
- type NamedServiceFactory
- type ServiceA
- type ServiceB
- type ServiceFactory
- type ServiceLocator
- type ServiceRegistry
- func (r *ServiceRegistry) GetServiceA() (ServiceA, error)
- func (r *ServiceRegistry) GetServiceB(serviceName string) (ServiceB, error)
- func (r *ServiceRegistry) GetServiceC() (subtest.ServiceC, error)
- func (r *ServiceRegistry) RegisterServiceA(factory ServiceFactory[ServiceA])
- func (r *ServiceRegistry) RegisterServiceB(serviceName string, factory NamedServiceFactory[ServiceB])
- func (r *ServiceRegistry) RegisterServiceC(factory ServiceFactory[subtest.ServiceC])
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircularDependencyError ¶
type CircularDependencyError struct { ServiceType string ServiceName string DependencyGraph []string }
CircularDependencyError is returned when there is a circular dependency between two services.
func (CircularDependencyError) Error ¶
func (e CircularDependencyError) Error() string
type NamedServiceFactory ¶
type NamedServiceFactory[T any] func(string, ServiceLocator) (T, error)
NamedServiceFactory creates a new named instance of T.
type ServiceFactory ¶
type ServiceFactory[T any] func(ServiceLocator) (T, error)
ServiceFactory creates a new instance of T.
type ServiceLocator ¶
type ServiceLocator interface { GetServiceA() (ServiceA, error) GetServiceB(name string) (ServiceB, error) GetServiceC() (subtest.ServiceC, error) }
ServiceLocator locates named services in a type-safe manner.
type ServiceRegistry ¶
type ServiceRegistry struct {
// contains filtered or unexported fields
}
ServiceRegistry allows registering service factories to construct new instances of a service. ServiceRegistry is also the primary {ServiceLocator} entrypoint.
func NewServiceRegistry ¶
func NewServiceRegistry() *ServiceRegistry
NewServiceRegistry instantiates a new {ServiceRegistry}.
func (*ServiceRegistry) GetServiceA ¶
func (r *ServiceRegistry) GetServiceA() (ServiceA, error)
GetServiceA retrieves an instance of {ServiceA}.
func (*ServiceRegistry) GetServiceB ¶
func (r *ServiceRegistry) GetServiceB(serviceName string) (ServiceB, error)
GetServiceB retrieves an instance of {ServiceB}.
func (*ServiceRegistry) GetServiceC ¶
func (r *ServiceRegistry) GetServiceC() (subtest.ServiceC, error)
GetServiceC retrieves an instance of {ServiceC}.
func (*ServiceRegistry) RegisterServiceA ¶
func (r *ServiceRegistry) RegisterServiceA(factory ServiceFactory[ServiceA])
RegisterServiceA registers a factory for {ServiceA}.
func (*ServiceRegistry) RegisterServiceB ¶
func (r *ServiceRegistry) RegisterServiceB(serviceName string, factory NamedServiceFactory[ServiceB])
RegisterServiceB registers a factory for {ServiceB}.
func (*ServiceRegistry) RegisterServiceC ¶
func (r *ServiceRegistry) RegisterServiceC(factory ServiceFactory[subtest.ServiceC])
RegisterServiceC registers a factory for {ServiceC}.