33Resource factories are used on Create operations to instantiate your resource.
44
55<!-- TOC -->
6- * [ Default factory for you resource] ( #default-factory-for-your-resource )
7- * [ Define your custom factory] ( #define-your-custom-factory )
8- * [ Use your custom method] ( #use-your-custom-method )
9- * [ Pass arguments to your method] ( #pass-arguments-to-your-method )
10- * [ Use a factory without declaring it] ( #use-a-factory-without-declaring-it )
11- * [ Use a callable for your custom factory] ( #use-a-callable-for-your-custom-factory )
6+ * [ Resource factories] ( #resource-factories )
7+ * [ Default factory for your resource] ( #default-factory-for-your-resource )
8+ * [ Inject the factory in your service] ( #inject-the-factory-in-your-service )
9+ * [ Define your custom factory] ( #define-your-custom-factory )
10+ * [ Use your custom method] ( #use-your-custom-method )
11+ * [ Pass arguments to your method] ( #pass-arguments-to-your-method )
12+ * [ Use a factory without declaring it] ( #use-a-factory-without-declaring-it- )
13+ * [ Use a callable for your custom factory] ( #use-a-callable-for-your-custom-factory )
1214<!-- TOC -->
1315
1416
@@ -18,6 +20,31 @@ By default, a resource factory is defined to your resource `Sylius\Component\Res
1820
1921It has a ` createNew ` method with no arguments.
2022
23+ ## Inject the factory in your service
24+
25+ If you are using Symfony autowiring, you can inject the resource factory using the right variable name.
26+
27+ ``` php
28+ namespace App;
29+
30+ use Sylius\Resource\Factory\FactoryInterface;
31+
32+ final class MyService
33+ {
34+ public function __construct(
35+ private FactoryInterface $bookFactory,
36+ ) {}
37+ }
38+ ```
39+
40+ In this example, the ` app.factory.book ` will be injected in your ` $bookFactory `
41+
42+ You can find the variable name using this debug command:
43+
44+ ``` shell
45+ $ bin/console debug:autowiring app.factory.book
46+ ```
47+
2148## Define your custom factory
2249
2350``` php
0 commit comments