5

I have recently been working on creating functionality for a module that requires certain content related to the module be deleted before the module itself can be uninstalled. https://www.drupal.org/project/commerce_pos/issues/3006353

I used an example for core's book module where I saw that a service called module_install.uninstall_validator and a ProxyClass called BookUninstallValidator were used in order to implement functionality similar to what I was attempting to achieve.

My question is thus: why is the module_install.uninstall_validator set to lazy and what exactly is a proxy class?

I have searched in the documentation but have been unable to find any useful explanation; so any here or links to such pages would be much appreciated.

1 Answer 1

1

It's a property of services classes provided by Symphony's dependency injection framework. Per its docs on lazy services:

In some cases, you may want to inject a service that is a bit heavy to instantiate, but is not always used inside your object. For example, imagine you have a NewsletterManager and you inject a mailer service into it. Only a few methods on your NewsletterManager actually use the mailer, but even when you don’t need it, a mailer service is always instantiated in order to construct your NewsletterManager.

In other words, proxy classes are quick-loading dummy stand-ins until the actual class methods are needed to do the heavy lifting. In this specific case, the Book uninstall validator isn't useful until it's needed during the book module uninstall so there's no need to fully instantiate the validator service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.