[DependencyInjection] remove code duplication from ContainerBuilder