Struct springtime_di::factory::ComponentFactory
source · pub struct ComponentFactory { /* private fields */ }Expand description
Generic factory for Component instances. Uses definitions from the ComponentDefinitionRegistry and scopes to create and store instances for reuse.
Implementations§
source§impl ComponentFactory
impl ComponentFactory
sourcepub fn new(
definition_registry: ComponentDefinitionRegistryPtr,
scope_factories: FxHashMap<String, ScopeFactoryPtr>
) -> Self
pub fn new( definition_registry: ComponentDefinitionRegistryPtr, scope_factories: FxHashMap<String, ScopeFactoryPtr> ) -> Self
Creates a new factory with given registry and scope factories. The factory map should include built-in SINGLETON and PROTOTYPE for maximum compatibility with components, since they are usually the most popular. This is not a hard requirement, but care needs to be taken to ensue no component uses them.
Trait Implementations§
source§impl ComponentInstanceProvider for ComponentFactory
impl ComponentInstanceProvider for ComponentFactory
source§fn primary_instance(
&mut self,
type_id: TypeId
) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
fn primary_instance( &mut self, type_id: TypeId ) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
Tries to return a primary instance of a given component. A primary component is either the
only one registered or one marked as primary.
source§fn instances(
&mut self,
type_id: TypeId
) -> Result<Vec<(ComponentInstanceAnyPtr, CastFunction)>, ComponentInstanceProviderError>
fn instances( &mut self, type_id: TypeId ) -> Result<Vec<(ComponentInstanceAnyPtr, CastFunction)>, ComponentInstanceProviderError>
Tries to instantiate and return all registered components for given type, stopping on first
error. Be aware this might be an expensive operation if the number of registered components
is high.
source§fn instance_by_name(
&mut self,
name: &str,
type_id: TypeId
) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
fn instance_by_name( &mut self, name: &str, type_id: TypeId ) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
Tries to return an instance with the given name and type.
Auto Trait Implementations§
impl !RefUnwindSafe for ComponentFactory
impl Send for ComponentFactory
impl Sync for ComponentFactory
impl Unpin for ComponentFactory
impl !UnwindSafe for ComponentFactory
Blanket Implementations§
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<CIP> TypedComponentInstanceProvider for CIPwhere
CIP: ComponentInstanceProvider + ?Sized,
impl<CIP> TypedComponentInstanceProvider for CIPwhere CIP: ComponentInstanceProvider + ?Sized,
source§fn primary_instance_typed<T>(
&mut self
) -> Result<Arc<T>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn primary_instance_typed<T>( &mut self ) -> Result<Arc<T>, ComponentInstanceProviderError>where T: Injectable + ?Sized,
Typesafe version of ComponentInstanceProvider::primary_instance.
source§fn primary_instance_option<T>(
&mut self
) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn primary_instance_option<T>( &mut self ) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where T: Injectable + ?Sized,
Tries to get an instance like TypedComponentInstanceProvider::primary_instance_typed does,
but returns
None on missing instance.source§fn instances_typed<T>(
&mut self
) -> Result<Vec<Arc<T>, Global>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn instances_typed<T>( &mut self ) -> Result<Vec<Arc<T>, Global>, ComponentInstanceProviderError>where T: Injectable + ?Sized,
Typesafe version of ComponentInstanceProvider::instances.
source§fn instance_by_name_typed<T>(
&mut self,
name: &str
) -> Result<Arc<T>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn instance_by_name_typed<T>( &mut self, name: &str ) -> Result<Arc<T>, ComponentInstanceProviderError>where T: Injectable + ?Sized,
Typesafe version of ComponentInstanceProvider::instance_by_name.
source§fn instance_by_name_option<T>(
&mut self,
name: &str
) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn instance_by_name_option<T>( &mut self, name: &str ) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where T: Injectable + ?Sized,
Tries to get an instance like TypedComponentInstanceProvider::instance_by_name_typed does,
but returns
None on missing instance.