2025-11-13 18:47:46 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
|
|
// ServiceRuntime is a helper struct embedded in services to provide access to the core application.
|
2025-11-14 14:33:58 +00:00
|
|
|
// It is generic and can be parameterized with a service-specific options struct.
|
2025-11-13 18:47:46 +00:00
|
|
|
type ServiceRuntime[T any] struct {
|
|
|
|
|
core *Core
|
|
|
|
|
opts T
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewServiceRuntime creates a new ServiceRuntime instance for a service.
|
2025-11-14 14:33:58 +00:00
|
|
|
// This is typically called by a service's constructor.
|
2025-11-13 18:47:46 +00:00
|
|
|
func NewServiceRuntime[T any](c *Core, opts T) *ServiceRuntime[T] {
|
|
|
|
|
return &ServiceRuntime[T]{
|
|
|
|
|
core: c,
|
|
|
|
|
opts: opts,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-14 14:33:58 +00:00
|
|
|
// Core returns the central core instance, providing access to all registered services.
|
2025-11-13 18:47:46 +00:00
|
|
|
func (r *ServiceRuntime[T]) Core() *Core {
|
|
|
|
|
return r.core
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Config returns the registered Config service from the core application.
|
2025-11-14 14:33:58 +00:00
|
|
|
// This is a convenience method for accessing the application's configuration.
|
2025-11-13 18:47:46 +00:00
|
|
|
func (r *ServiceRuntime[T]) Config() Config {
|
|
|
|
|
return r.core.Config()
|
|
|
|
|
}
|