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
-
- Object
- ObjectFactory<
T> - ObjectProvider
- 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
trueif no objects are available.no setter - isNotEmpty → bool
-
Returns
trueif 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
Tin 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< ? supplier]) → Future<T> >ObjectHolder< T> ?> -
Retrieves the object if available, or returns
nullif none exist. -
getIfUnique(
[Supplier< ObjectHolder< ? supplier]) → Future<T> >ObjectHolder< T> ?> -
Retrieves the object only if exactly one instance exists, or returns
null. -
ifAvailable(
Consumer< ObjectHolder< consumer) → Future<T> >void> -
Executes
consumerif the object is available. -
ifUnique(
Consumer< ObjectHolder< consumer) → Future<T> >void> -
Executes
consumeronly 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
GenericStreamof 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