ObjectProvider<T> class abstract

A flexible, functional-style provider interface for retrieving and interacting with pods or objects of a particular type.

This is an extension of ObjectFactory and Iterable that provides advanced options for conditional retrieval, functional callbacks, filtering, and ordering.


🚀 Usage

final ObjectProvider<MyService> provider = ...;

// Get the object, or throw if none or multiple exist
MyService service = provider.getObject();

// Get if available, or null if none exist
MyService? maybeService = provider.getIfAvailable();

// Get a default if not present
MyService service = provider.getIfAvailableOrDefault(() => MyService());

// Use a consumer if available
provider.ifAvailable((s) => s.start());

// Stream through all instances
provider.stream().forEach(print);

🔍 Filtering and Ordering

You can stream all matching pods ordered by Ordered or PriorityOrdered:

provider.orderedStream().forEach(print);

Or with a custom type filter (using your Class<T> metadata):

provider.orderedStreamWithFilter((clazz) => clazz.name.contains('MyType'));

Note: By default, non-singletons are included. Support for filtering them is not yet implemented.

Inheritance
Implementers
Annotations
  • @Generic.new(ObjectProvider)

Constructors

ObjectProvider()
A flexible, functional-style provider interface for retrieving and interacting with pods or objects of a particular type.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Returns true if no objects are available.
no setter
isNotEmpty bool
Returns true if at least one object is available.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

chain<R>(ObjectFactory<R> nextFactory(T)) Future<ObjectFactory<R>>
Creates a new ObjectFactory that uses this factory's output as input to another factory.
inherited
copyWith({ObjectFactoryFunction<T>? creator}) ObjectFactory<T>
Creates a copy of this ObjectFactory with a new creator function.
inherited
createMultiple(int count) Future<List<T>>
Creates multiple instances of type T in a single call.
inherited
get([List<ArgumentValue>? args]) FutureOr<ObjectHolder<T>>
Retrieves the single object instance or throws if none or more than one found.
override
getIfAvailable([Supplier<ObjectHolder<T>>? supplier]) Future<ObjectHolder<T>?>
Retrieves the object if available, or returns null if none exist.
getIfUnique([Supplier<ObjectHolder<T>>? supplier]) Future<ObjectHolder<T>?>
Retrieves the object only if exactly one instance exists, or returns null.
ifAvailable(Consumer<ObjectHolder<T>> consumer) Future<void>
Executes consumer if the object is available.
ifUnique(Consumer<ObjectHolder<T>> consumer) Future<void>
Executes consumer only if exactly one instance is available.
iterator() Iterator<T>
Returns an iterator over all available objects.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
stream() → GenericStream<ObjectHolder<T>>
Returns a GenericStream of all available objects.
toList() List<T>
Returns a list of all available objects.
toString() String
Returns a string representation of this ObjectFactory.
inherited
withSideEffect(void sideEffect(T)) Future<ObjectFactory<T>>
Creates a new factory that performs a side effect after object creation.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited