pub struct ProviderRegistry { /* private fields */ }Expand description
A registry of provider factories for dynamic provider instantiation.
The registry maintains a map of provider names to their factories, allowing providers to be created from configuration at runtime.
§Thread Safety
The registry is thread-safe and can be accessed concurrently.
Registration and lookup use interior mutability via RwLock.
§Global vs Local Registries
Use ProviderRegistry::global() for the shared global registry,
or create local registries with ProviderRegistry::new() for
testing or isolated contexts.
Implementations§
Source§impl ProviderRegistry
impl ProviderRegistry
Sourcepub fn global() -> &'static Self
pub fn global() -> &'static Self
Returns the global shared registry.
Provider crates should register their factories here on initialization. Application code can then build providers from configuration without knowing which providers are available at compile time.
Sourcepub fn register(&self, factory: Box<dyn ProviderFactory>) -> &Self
pub fn register(&self, factory: Box<dyn ProviderFactory>) -> &Self
Registers a provider factory (chainable Arc version).
Use this when you want to share the factory instance.
Sourcepub fn unregister(&self, name: &str) -> bool
pub fn unregister(&self, name: &str) -> bool
Unregisters a provider by name.
Returns true if the provider was registered and removed.
Sourcepub fn build(
&self,
config: &ProviderConfig,
) -> Result<Box<dyn DynProvider>, LlmError>
pub fn build( &self, config: &ProviderConfig, ) -> Result<Box<dyn DynProvider>, LlmError>
Builds a provider from configuration.
Looks up the factory by config.provider and delegates to it.
§Errors
Returns LlmError::InvalidRequest if no factory is registered
for the requested provider name.