WordPress at Your Fingertips
function is not described


Container::factory() public WC 1.0

Public api for adding a factory to the container.

Factory dependencies will have the instantiation callback invoked every time the dependency is requested.

Typical Usage:

$container->register( MyClass::class, $container->factory( $mycallback ) );

{} It's a method of the class: Container{}

No Hooks.


FactoryType. An instance of the FactoryType dependency.


$Container = new Container();
$Container->factory( $instantiation_callback );
$instantiation_callback(Closure) (required)
This will be invoked when the dependency is required. It will receive an instance of this container so the callback can retrieve dependencies from the container.

Code of Container::factory() WC 5.6.0

public function factory( Closure $instantiation_callback ) {
	return new FactoryType( $instantiation_callback );