doctrine/DoctrineMigrationsBundle

Migration dependency injection in Symfony 7.0

TomBrouws opened this issue · 11 comments

The current documentation (https://symfony.com/bundles/DoctrineMigrationsBundle/current/index.html#migration-dependencies) refers to using ContainerAwareInterface in order to inject the entire container into a migration. In Symfony 6.4 this interface is deprecated, and it is removed in 7.0. (symfony/symfony-docs#18440)

Is there a recommended way to tackle dependency injection for migrations in Symfony 7.0? Are code changes needed in this library in order to replicate the old functionality, or is an update of the docs sufficient?

Is there a recommended way to tackle dependency injection for migrations in Symfony 7.0?

No. As you said, the upstream interface is gone. We don't have a replacement (yet?).

Are code changes needed in this library in order to replicate the old functionality,

Yes.

or is an update of the docs sufficient?

The docs change would currently be to remove the mention of it from the docs or at least add a note that the feature is gone when upgrading to Symfony 7.

That being said, injecting the whole container is highly discouraged by Symfony. If we were to build a replacement, we should either:

  • Make it possible (not mandatory!) to register migrations as services
  • Inject a service locator instead, e.g. by allowing migrations to be service subscribers.

Thanks for your reply. Good to know there's no replacement yet.

injecting the whole container is highly discouraged by Symfony

Yes, by 'replicate' I meant in a way that is idiomatic in the newest Symfony version, so your suggestions make sense.

Please, give an working example of custom migration factories that should be used to inject additional dependencies into migrations.

Please, give an working example of custom migration factories that should be used to inject additional dependencies into migrations.

Nobody can give you a working example for a feature that doesn't exist.