For developers: Implement the definition class
Your definition class should always inherit from DefinitionBase. It should also implement the interface implemented in the previous step.
The next thing your definition class should do is provide 2 constructors: one empty constructor and another one which takes a single configuration element as an argument. This is the same configuration element that we will implement in the next step. Both constructors should invoke the constructors of the base class with corresponding signatures. They don’t need to execute any code. Sitefinity CMS uses these constructors to create instances of your classes, and they are invoked automatically.
public
CustomDefinition()
:
base
()
{
}
public
CustomDefinition(ConfigElement parent)
:
base
(parent)
{
}
After you have implemented the two constructors, you should of course implement all properties specified by your custom interface. Those properties should not use automatic getters and setters. Instead, they should resolve their values by calling the ResolveProperty method of the base class. This is very important and your definitions will not work if your properties do not resolve values like this. The ResolveProperty method is the entry point for the chain of responsibility pattern we described earlier.
public
string
CustomHeaderText
{
get
{
return
this
.ResolveProperty<
string
>(
"CustomHeaderText"
,
this
.customHeaderText);
}
set
{
this
.customHeaderText = value;
}
}
private
string
customHeaderText;
There are several arguments you should pass to the ResolveProperty method.
- The first is the generic argument. It specifies the return type of the property whose value you are resolving.
- The first actual (non-generic) argument is a string value containing the name of your property. This should be exactly the name of the property whose getter you are implementing. It is the same in the interface, definition class and configuration element.
- The last argument you pass to the ResolveProperty method is the field in the definition class which will contain the resolved value. This means that you need to implement a private field for each property.
When you have the two constructors and all properties from the interface, the implementation of the definition class is done.