copyWith method

ObjectFactory<T> copyWith({
  1. ObjectFactoryFunction<T>? creator,
})

Creates a copy of this ObjectFactory with a new creator function.

This method is useful when you want to create a similar factory but with slight modifications to the creation logic.

creator: Optional new creator function (uses current if null) Returns a new ObjectFactory instance with the specified creator

Example:

final originalFactory = ObjectFactory<String>(() => 'hello');

// Create a factory with different creation logic
final upperCaseFactory = originalFactory.copyWith(
  creator: () => 'HELLO',
);

Implementation

ObjectFactory<T> copyWith({ObjectFactoryFunction<T>? creator}) {
  return SimpleObjectFactory<T>(([args]) => creator?.call(args) ?? get(args));
}