Skip to main content

Crate ferroui_dependency_injection

Crate ferroui_dependency_injection 

Source
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§

ActivatorUtilities
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.
AsyncServiceScope
Wraps any synchronous scope, preferring its async-disposal capability when available.
DefaultServiceProviderFactory
Dependency
A constructor parameter’s call site, used without running user code during validation.
ObjectFactory
ServiceCollection
Ordered registrations; building a provider snapshots this collection.
ServiceDescriptor
A registration. Construct typed factories with new or from_factory; erased registration exists for adapters. Instance registrations are externally owned and never disposed.
ServiceIdentifier
ServiceKey
An arbitrary value key, compared by type and value. None represents an unkeyed service.
ServiceProvider
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.
ServiceProviderOptions
ServiceScope
ServiceType

Enums§

DependencyKind
ServiceError
ServiceKeyLookupMode
ServiceLifetime

Traits§

IAsyncDisposable
Async disposal uses FerroUI’s local task executor; no external runtime is required.
IKeyedServiceProvider
IServiceCollection
IServiceProvider
IServiceProviderFactory
IServiceProviderIsKeyedService
IServiceProviderIsService
IServiceScope
IServiceScopeFactory
ISupportRequiredService
Required-service resolution for alternate providers (ISupportRequiredService.cs).
ServiceProviderServiceExtensions

Functions§

erase_service
unerase_service

Type Aliases§

ErasedFactory
ErasedService
ServiceResult