SimpleObjectFactory<T> class
Default implementation of the ObjectFactory interface that uses a creator function.
This class provides a simple, flexible way to create objects on demand using a provided creator function. It's the standard implementation used throughout the Jetleaf framework for object creation scenarios.
Key features:
- Simple delegation to a creator function
- Type-safe generic implementation
- Lightweight and efficient
- No internal state or caching
- Easy to compose and decorate
Usage scenarios:
- Pod instantiation in dependency injection
- Prototype scope object creation
- Factory method implementations
- Ad-hoc object creation requirements
- Decorator and wrapper patterns
Example usage:
// Create a factory for UserService
final userServiceFactory = _ObjectFactory<UserService>(
() => UserService()..initialize(),
);
// Create instances as needed
final userService1 = userServiceFactory.getObject();
final userService2 = userServiceFactory.getObject();
// Each call creates a new instance
print(identical(userService1, userService2)); // false
- Inheritance
-
- Object
- ObjectFactory<
T> - SimpleObjectFactory
- Annotations
-
- @Generic(SimpleObjectFactory)
Constructors
-
SimpleObjectFactory(ObjectFactoryFunction<
T> creator) - Default implementation of the ObjectFactory interface that uses a creator function.
Properties
-
creator
→ ObjectFactoryFunction<
T> -
The creator function that produces new instances of type
T.final - hashCode → int
-
The hash code for this object.
no setterinherited
- 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> > -
Returns an instance of the object managed by this factory.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
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