For developers: Chain of responsibility
Definitions and configurations allow us to store control properties in memory, and also in configuration (whether that would be files or the database). However, as all normal ASP.NET controls, our controls can have their properties set directly on the control instance. This is done whenever you put one control on a page, open its designer and change a value. So we have three places where property values are kept:
- In the control instance itself
- In the in-memory definition
- In the configuration element (file or DB)
When the control logic executes, it reads those values from one of those places, but in what order?
We’ve implemented the chain of responsibility pattern with definitions. In short this means that for each property a control uses, it goes through the following chain:
- It looks for a value of the property set directly to the instance of the control
- If null, then it looks for a value in the definition in-memory
- If null, then it looks for a value in the configuration element
This order is important. If the instance property didn’t come first, we would not be able to edit properties through the designers. Values that we set in the Sitefinity CMS page editor would be neglected. That’s why we want to read instance values first.
For more information about the chain of responsibility pattern, you can read http://www.dofactory.com/Patterns/PatternChain.aspx.