Writing extensions: count with autowiring or not?

3 years ago

Michal Vyšinský
Member | 614
+
+1
-

Hi,

this is my tweet: https://twitter.com/…242961301506 and @TomášVotruba was right that this is rather topic for forum.

Example is better than explaining the idea: https://github.com/…rill/pull/11

I wanted to use that library (register the extension) twice. Before that PR I couldn't because DI builder complained about multiple services of the same type. So I've added support for turning autowiring off for whole extension. But because of ‘internal’ services in the extension I had to also ‘inject’ those services manually in the extension.

After some time I think it is correct solution. What do you think?

Edit: and another question – would it make sense to add feature to turn autowiring off for any extension directly to the framework?

Last edited by Michal Vyšinský (2016-06-17 12:58)

3 years ago

Tomáš Votruba
Moderator | 1154
+
+2
-

Hi, more clear and standard way to approach this would be allowing multiple connections.
Same as for Nette\Database (see docs), Doctrine (see Kdyby forum) or any other extension allowing 1..n instance(s).

extensions:
    mandrill: DotBlue\Mandrill\NetteBridge\DI\MandrillExtension

mandrill:
    connections:
        firstMandrill:
            apiKey: "your API k"
        secondMandrill:
            apiKey: "different API key"

Last edited by Tomáš Votruba (2016-06-17 15:19)

3 years ago

Michal Vyšinský
Member | 614
+
0
-

Thanks for your reply. Well for this case it makes sense to have multiple connections. But what about some extension which you would really like to register twice with a different configuration?

Maybe bad example and maybe I am trying to solve something which is not a problem but for example translations (maybe kdyby/translation) – in case you would like to have a completely different configuration for frontend and backend – wouldn't be easier to have extension registered twice? So maybe it would be useful for me (as the user of the library) to have the option to turn off autowiring of all services provided by the extension.

As I wrote: I don't have concrete example and it is just an idea so maybe I am just thinking about it way too much :)

3 years ago

Tomáš Votruba
Moderator | 1154
+
0
-

Registering extension twice would be like using 2 containers. It is possible, yet not standard way to approach this.

Any setup should be multiplicable inside ones extension configuration.

Also, rather than finding theoretical use case, I'd focus on real issue and how to solve it at best.

3 years ago

Michal Vyšinský
Member | 614
+
+1
-

Ok. Thanks for discussion. You are right that talking about theory is useless. In case I will encounter some real use case I will continue in discussion.