pub struct Container { /* private fields */ }Expand description
See the crate docs.
Implementations§
Source§impl Container
impl Container
pub fn new() -> Container
Sourcepub fn epoch(&self) -> u64
pub fn epoch(&self) -> u64
Changes whenever any binding, alias, extender, contextual binding, tag or callback changes, whenever an instance is forgotten, and at every request start and end. Resolving never changes it. A cache built at another epoch must re-check; one built at this epoch is current.
Sourcepub fn registering(&self, lifetime: Lifetime) -> Registering<'_>
pub fn registering(&self, lifetime: Lifetime) -> Registering<'_>
Registrations made while the returned guard lives get lifetime (a bridge sets Request around PHP’s calls).
Sourcepub fn set_autowirer(&self, autowirer: Rc<dyn Autowirer>)
pub fn set_autowirer(&self, autowirer: Rc<dyn Autowirer>)
Who builds keys that have no entry.
pub fn bind( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
pub fn bind_if( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
pub fn singleton( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
pub fn singleton_if( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
Sourcepub fn scoped(
&self,
key: &str,
factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static,
)
pub fn scoped( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
Shared until the request ends.
pub fn scoped_if( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
pub fn instance(&self, key: &str, value: Resolved)
Sourcepub fn bind_foreign(
&self,
key: &str,
factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static,
)
pub fn bind_foreign( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
A binding made by a language bridge: Container::is_foreign is true while it is on top.
Sourcepub fn singleton_foreign(
&self,
key: &str,
factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static,
)
pub fn singleton_foreign( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
As Container::bind_foreign, shared.
Sourcepub fn scoped_foreign(
&self,
key: &str,
factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static,
)
pub fn scoped_foreign( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )
As Container::bind_foreign, shared until the request ends.
Sourcepub fn instance_foreign(&self, key: &str, value: Resolved)
pub fn instance_foreign(&self, key: &str, value: Resolved)
An instance registered by a language bridge.
Sourcepub fn bind_port<P: ?Sized + 'static>(
&self,
key: &str,
factory: impl Fn(&Container, &Params) -> Result<Rc<P>, ContainerError> + 'static,
)
pub fn bind_port<P: ?Sized + 'static>( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Rc<P>, ContainerError> + 'static, )
Binds a port (a trait object) by its key.
Sourcepub fn singleton_port<P: ?Sized + 'static>(
&self,
key: &str,
factory: impl Fn(&Container, &Params) -> Result<Rc<P>, ContainerError> + 'static,
)
pub fn singleton_port<P: ?Sized + 'static>( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Rc<P>, ContainerError> + 'static, )
As Container::bind_port, shared.
Sourcepub fn make_port<P: ?Sized + 'static>(
&self,
key: &str,
) -> Result<Rc<P>, ContainerError>
pub fn make_port<P: ?Sized + 'static>( &self, key: &str, ) -> Result<Rc<P>, ContainerError>
The value of a port binding, as its trait object.
Sourcepub fn alias(&self, key: &str, alias: &str)
pub fn alias(&self, key: &str, alias: &str)
alias resolves to key. Panics on an alias cycle (use Container::try_alias to handle it).
pub fn try_alias(&self, key: &str, alias: &str) -> Result<(), ContainerError>
pub fn is_alias(&self, key: &str) -> bool
Sourcepub fn get_alias(&self, key: &str) -> String
pub fn get_alias(&self, key: &str) -> String
The key an alias finally resolves to (the key itself when it is no alias).
Sourcepub fn extend(
&self,
key: &str,
extender: impl Fn(Resolved, &Container) -> Result<Resolved, ContainerError> + 'static,
)
pub fn extend( &self, key: &str, extender: impl Fn(Resolved, &Container) -> Result<Resolved, ContainerError> + 'static, )
Decorates every value key resolves to, from now on; an already shared value is decorated at once.
pub fn when(&self, consumer: &str) -> When<'_>
pub fn tag(&self, keys: &[&str], tag: &str)
Sourcepub fn tagged(&self, tag: &str) -> Result<Vec<Resolved>, ContainerError>
pub fn tagged(&self, tag: &str) -> Result<Vec<Resolved>, ContainerError>
Every key with tag, resolved, in tag order.
pub fn before_resolving( &self, key: Option<&str>, callback: impl Fn(&str, &Container) + 'static, )
pub fn resolving( &self, key: Option<&str>, callback: impl Fn(&Resolved, &Container) + 'static, )
pub fn after_resolving( &self, key: Option<&str>, callback: impl Fn(&Resolved, &Container) + 'static, )
Sourcepub fn sharing(&self, key: &str) -> Option<Sharing>
pub fn sharing(&self, key: &str) -> Option<Sharing>
How the entry answering key (after aliases) shares its value: an instance counts as a singleton; None when
key has no entry.
Sourcepub fn bound(&self, key: &str) -> bool
pub fn bound(&self, key: &str) -> bool
The same as Container::has (Laravel’s bound).
Sourcepub fn generation(&self, key: &str) -> u64
pub fn generation(&self, key: &str) -> u64
Changes whenever what key (or what it aliases) resolves to may change: a binding, instance, extender or
forgetting. A cache of a resolved value is current while this is unchanged.
Sourcepub fn is_foreign(&self, key: &str) -> bool
pub fn is_foreign(&self, key: &str) -> bool
Whether the entry answering for key now was registered by a language bridge.
pub fn make(&self, key: &str) -> Result<Resolved, ContainerError>
Sourcepub fn make_with(
&self,
key: &str,
params: &Params,
) -> Result<Resolved, ContainerError>
pub fn make_with( &self, key: &str, params: &Params, ) -> Result<Resolved, ContainerError>
Builds key with params; never returns nor becomes a shared instance when params is not empty.
Sourcepub fn factory<'a>(
&'a self,
key: &str,
) -> impl Fn() -> Result<Resolved, ContainerError> + 'a
pub fn factory<'a>( &'a self, key: &str, ) -> impl Fn() -> Result<Resolved, ContainerError> + 'a
A function that makes key each time it is called.
Sourcepub fn resolved_in_request(&self, key: &str) -> bool
pub fn resolved_in_request(&self, key: &str) -> bool
Whether key was resolved since the request started (a cached shared value counts).
Sourcepub fn start_request(&self)
pub fn start_request(&self)
Starts a request: nothing counts as resolved in it yet.
Sourcepub fn forget_instance(&self, key: &str)
pub fn forget_instance(&self, key: &str)
Drops the shared value of key (and its registered instances).
Sourcepub fn forget_instances(&self)
pub fn forget_instances(&self)
Drops every shared value and registered instance.
Sourcepub fn forget_scoped_instances(&self)
pub fn forget_scoped_instances(&self)
Drops every scoped value; singletons stay.
Sourcepub fn end_request(&self)
pub fn end_request(&self)
Ends the request: removes every Request registration (bindings, instances, aliases, extenders, contextual
bindings, tags, callbacks) and every scoped value. Each key answers with its worker-lifetime entry again.