Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

BitExpert Blog:
Why using code as DI config is a win!
Jul 26, 2017 @ 15:58:21

In a post to the bitExpert.de site Stephan Hochdörfer explains why he thinks that using code over configuration in a DI container is a better approach than static configuration definitions.

In my recent talk on introducing Disco - the DI container with the damn coolest name(tm) - I talk about why I believe that using XML or any other non-code configuration (YAML, JSON, ...) is not a good idea. This stirred some twitter discussion recently which led to this blog post.

Just for the record, for a very long time I was part of the XML camp - just browse my collection of old talks to see for yourself. I praised XML a lot as being the only true DI configuration format.

He then goes through some of the main issues he sees with using something like XML for the dependency container's configuration:

  • An XML editor won't give you code-completion for PHP classes or methods.
  • Refactoring won't work properly in an XML configuration file.
  • An XML editor is not capable of doing proper type checks.
  • XML is just too verbose.

For each item he provides a brief explanation and an example of XML where it helps to illustrate the point.

tagged: xml configuration code disco dependency injection container opinion

Link: https://blog.bitexpert.de/blog/why-using-code-as-di-config-is-a-win/


Trending Topics: