Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[RFC][Console][DI] Simplify adding DI container to CLI apps #27479

Closed
@PabloKowalczyk

Description

@PabloKowalczyk

Description
Hello, recently i've became the Crunz maintainer, after some review i've realized that Crunz doesn't use DI container - this means static calls and no way to write sensible test. In the meantime @TomasVotruba published some blog posts about adding DI container to CLI apps, as you can see there is no standard/recommended way to add DI to CLI app.
One approach is to copy some code from HttpKernel as i do in Crunz , but maintaining it is not nice nor easy. Nobody wants to reinvent the wheel.
Another approach, as suggested in above blog post, is to use Kernel provded by http-kernel package but i do not like this idea because it is weird to have full http support in CLI app :)

IMO there are three ways to increase DX and easy development of CLI apps with DI container:

  1. Introduce something like "cli-kernel" - like http-kernel (and framework-bundle) but for CLI. IMO this is the best way because developers can also have other features, out-of-the-box, like autoconfigure Symfony commands, easy access to container in test env and many others.
  2. Extend Symfony\Component\Console\Application to support DI natively. For example by decorator.
  3. Improve docs :) If you think that above options aren't good it would be very nice to at least add recommended way to glue DI and Console.

What do you think?
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConsoleRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions