pub struct ServiceContainer { /* private fields */ }Expand description
Service container for dependency injection and service management.
The service container holds references to core services and provides a centralized way to access them throughout the application. It manages the lifecycle of services and ensures proper dependency injection.
§Design Principles
- Single Source of Truth: All services are managed through the container
- Dependency Injection: Components receive dependencies explicitly
- Configuration Isolation: Services are decoupled from global configuration
- Test Friendliness: Easy to mock and test individual components
§Examples
use subx_cli::core::ServiceContainer;
use subx_cli::config::ProductionConfigService;
use std::sync::Arc;
let config_service = Arc::new(ProductionConfigService::new()?);
let container = ServiceContainer::new(config_service)?;
// Access services through container
let config_service = container.config_service();
let factory = container.component_factory();Implementations§
Source§impl ServiceContainer
impl ServiceContainer
Sourcepub fn new(config_service: Arc<dyn ConfigService>) -> Result<Self>
pub fn new(config_service: Arc<dyn ConfigService>) -> Result<Self>
Sourcepub fn config_service(&self) -> &Arc<dyn ConfigService>
pub fn config_service(&self) -> &Arc<dyn ConfigService>
Get a reference to the configuration service.
Returns a reference to the configuration service managed by this container.
Sourcepub fn component_factory(&self) -> &ComponentFactory
pub fn component_factory(&self) -> &ComponentFactory
Get a reference to the component factory.
Returns a reference to the component factory that can create configured instances of core components.
Sourcepub fn reload(&mut self) -> Result<()>
pub fn reload(&mut self) -> Result<()>
Reload all services and components.
This method triggers a reload of the configuration service and recreates the component factory with the updated configuration. This is useful for dynamic configuration updates.
§Errors
Returns an error if configuration reloading or factory recreation fails.
Auto Trait Implementations§
impl Freeze for ServiceContainer
impl !RefUnwindSafe for ServiceContainer
impl Send for ServiceContainer
impl Sync for ServiceContainer
impl Unpin for ServiceContainer
impl !UnwindSafe for ServiceContainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.