[DependencyInjection] remove code duplication from ContainerBuilder
merged branch tgabi333/di_minor_code_duplication (PR #8949)

This PR was merged into the master branch.

Discussion
----------

[DependencyInjection] remove code duplication from ContainerBuilder

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  |no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

485fb15 [DependencyInjection] remove code duplication from ContainerBuilder