New Dependencies for Existing Modules

Dependency injection is a wonderful technique utilized in object-orientated programming to promote loose coupling of components, and Orchard CMS has taken full advantage of it. There isn't a service or class providing functionality in Orchard CMS that isn't replaceable by using dependency injection in your own custom module. Making your own services injectable is as simple as creating an class that implements interface IDepedency.

While there is nothing wrong with that code, not being mindful of which modules are enabled could cause the dreaded yellow screen to show up.

I ran into this when we decided to refactor a current service being used by only one module into one being used by several. To facilitate this reuse we moved the service into its own module. After setting up the code and testing it for the first time, I got the above error.

This was because I made a currently enabled module suddenly dependent on a module that was not enabled. Since this error breaks the whole site, you have to revert to fix the problem beforehand.

  1. Disable all modules getting new dependencies.
  2. Develop new module that is the dependency.
  3. Enable the new module and all modules refactored to use it.

No Comments