Expand description
A UI-independent, thread-local port of Microsoft.Extensions.DependencyInjection.
Services (including trait objects) are identified by TypeId and returned as Rc<S>.
Collections are mutable; built providers are immutable snapshots. Dispose providers and
scopes explicitly. Constructor factories declare dependencies for build-time validation;
arbitrary closures are opaque, as delegate factories are upstream.
use ferroui_dependency_injection::*;
use std::rc::Rc;
let mut services = ServiceCollection::new();
services.add_singleton::<String, _>(|_| Ok(Rc::new("hello".into())));
let provider = services.build_service_provider(Default::default())?;
assert_eq!(&*provider.get_required_service::<String>()?, "hello");
provider.dispose()?;Macros§
- service_
factory - Writes a factory and its validation metadata from typed constructor parameters.
Structs§
- Activator
Utilities - Creates unregistered instances from the same factories as registrations. Such instances belong to the caller, not to a provider’s disposal list. Explicit constructor arguments can be captured by the factory; Rust checks their types and the selected constructor.
- Async
Service Scope - Wraps any synchronous scope, preferring its async-disposal capability when available.
- Default
Service Provider Factory - Dependency
- A constructor parameter’s call site, used without running user code during validation.
- Object
Factory - Service
Collection - Ordered registrations; building a provider snapshots this collection.
- Service
Descriptor - A registration. Construct typed factories with
neworfrom_factory; erased registration exists for adapters. Instance registrations are externally owned and never disposed. - Service
Identifier - Service
Key - An arbitrary value key, compared by type and value.
Nonerepresents an unkeyed service. - Service
Provider - Cloneable handle to a root provider or a scope. Neither Send nor Sync: services stay on the creating thread. Cloning shares state; it never creates a new scope.
- Service
Provider Options - Service
Scope - Service
Type
Enums§
Traits§
- IAsync
Disposable - Async disposal uses FerroUI’s local task executor; no external runtime is required.
- IKeyed
Service Provider - IService
Collection - IService
Provider - IService
Provider Factory - IService
Provider IsKeyed Service - IService
Provider IsService - IService
Scope - IService
Scope Factory - ISupport
Required Service - Required-service resolution for alternate providers (
ISupportRequiredService.cs). - Service
Provider Service Extensions