pub struct Catalog(/* private fields */);Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn builder() -> CatalogBuilder
pub fn builder() -> CatalogBuilder
Returns a CatalogBuilder used to initialize a Catalog.
Sourcepub fn builder_chained(&self) -> CatalogBuilder
pub fn builder_chained(&self) -> CatalogBuilder
Returns a CatalogBuilder that is chained to this Catalog and
thus “inherits” all previous builders and bindings. Chaining catalogs is
a very useful technique to add dynamic values that are not known
upfront. For example, catalog chaining can be used in HTTP server
middleware to add authorization information about the caller after
validating the security token, or to open a database transaction and
make it available for injection to all subsequently instantiated
services.
Sourcepub fn weak_ref(&self) -> CatalogWeakRef
pub fn weak_ref(&self) -> CatalogWeakRef
Returns a weak reference to the catalog chain. Weak reference is useful
when you want to keep using Catalog as a factory for complex
instantiation logic, but don’t want to own the strong reference that
prevents it to be dropped. It’s imperative to use weak references in
Singleton and other caching scopes, as otherwise you may end up with
cyclic references that prevent all instances from ever being cleaned up.
Sourcepub fn builders<'a>(&'a self) -> Box<dyn Iterator<Item = &'a dyn Builder> + 'a>
pub fn builders<'a>(&'a self) -> Box<dyn Iterator<Item = &'a dyn Builder> + 'a>
Returns an iterator over all registered instance Builders.
Sourcepub fn builders_for<'a, Iface>(
&'a self,
) -> Box<dyn Iterator<Item = TypecastBuilder<'a, Iface>> + 'a>where
Iface: 'static + ?Sized,
pub fn builders_for<'a, Iface>(
&'a self,
) -> Box<dyn Iterator<Item = TypecastBuilder<'a, Iface>> + 'a>where
Iface: 'static + ?Sized,
Returns an iterator over Builders bound to a specific interface
type.
Sourcepub fn builders_for_with_meta<'a, Iface, Meta>(
&'a self,
pred: impl Fn(&Meta) -> bool + Copy + 'a,
) -> Box<dyn Iterator<Item = TypecastBuilder<'a, Iface>> + 'a>where
Iface: 'static + ?Sized,
Meta: 'static,
pub fn builders_for_with_meta<'a, Iface, Meta>(
&'a self,
pred: impl Fn(&Meta) -> bool + Copy + 'a,
) -> Box<dyn Iterator<Item = TypecastBuilder<'a, Iface>> + 'a>where
Iface: 'static + ?Sized,
Meta: 'static,
Filters Builders by bound interface type and metadata predicate.
Sourcepub fn get<Spec>(&self) -> Result<Spec::ReturnType, InjectionError>where
Spec: DependencySpec + 'static,
pub fn get<Spec>(&self) -> Result<Spec::ReturnType, InjectionError>where
Spec: DependencySpec + 'static,
Resolves and attempts to get an instance by a specific dependency
DependencySpec.