pub struct ScopeBuilder { /* private fields */ }Expand description
Builder for creating scoped containers with pre-configured services.
Useful when you have a standard set of services to register per-scope.
§Examples
use dependency_injector::{Container, ScopeBuilder};
use std::sync::atomic::{AtomicU64, Ordering};
static COUNTER: AtomicU64 = AtomicU64::new(0);
#[derive(Clone)]
struct RequestId(u64);
let root = Container::new();
let builder = ScopeBuilder::new()
.with_transient(|| RequestId(COUNTER.fetch_add(1, Ordering::SeqCst)));
let scope1 = builder.build(&root);
let scope2 = builder.build(&root);
// Each scope gets its own servicesImplementations§
Source§impl ScopeBuilder
impl ScopeBuilder
Sourcepub fn with_singleton<T, F>(self, factory: F) -> Self
pub fn with_singleton<T, F>(self, factory: F) -> Self
Add a singleton factory to run in each scope.
Sourcepub fn with_transient<T, F>(self, factory: F) -> Self
pub fn with_transient<T, F>(self, factory: F) -> Self
Add a transient factory.
Sourcepub fn build(&self, parent: &Container) -> ScopedContainer
pub fn build(&self, parent: &Container) -> ScopedContainer
Build a scoped container with all registered services.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScopeBuilder
impl !RefUnwindSafe for ScopeBuilder
impl Send for ScopeBuilder
impl Sync for ScopeBuilder
impl Unpin for ScopeBuilder
impl UnsafeUnpin for ScopeBuilder
impl !UnwindSafe for ScopeBuilder
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
Mutably borrows from an owned value. Read more
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging