camel_api/producer.rs
1//! Producer context for dependency injection.
2//!
3//! This module provides [`ProducerContext`] for holding shared dependencies
4//! that producers need access to, such as the runtime command/query handle.
5
6use crate::runtime::RuntimeHandle;
7use std::sync::Arc;
8
9/// Context provided to producers for dependency injection.
10///
11/// `ProducerContext` holds references to shared infrastructure components
12/// that producers may need access to during message production.
13#[derive(Clone)]
14pub struct ProducerContext {
15 runtime: Option<Arc<dyn RuntimeHandle>>,
16}
17
18impl ProducerContext {
19 /// Creates a new empty `ProducerContext`.
20 pub fn new() -> Self {
21 Self { runtime: None }
22 }
23
24 /// Attaches a runtime command/query handle.
25 pub fn with_runtime(mut self, runtime: Arc<dyn RuntimeHandle>) -> Self {
26 self.runtime = Some(runtime);
27 self
28 }
29
30 /// Returns the runtime command/query handle, if configured.
31 pub fn runtime(&self) -> Option<&Arc<dyn RuntimeHandle>> {
32 self.runtime.as_ref()
33 }
34}
35
36impl Default for ProducerContext {
37 fn default() -> Self {
38 Self::new()
39 }
40}