DataSource API: Configuration Attribute
The [Configuration]
attribute marks properties on a DataSource as configuration properties.
This allows you to then provide configuration values when getting a DataSource using the Kit.Data or to make it configurable in VisualQuery.
Example:
/// <summary>
/// Should the Modified date be included in serialization
/// </summary>
[Configuration]
public string IncludeModified => Configuration.GetThis();
/// <summary>
/// Should the Relationships be included as CSV like "42,27,999".
/// Default is `false` in which case they are sub-objects.
/// </summary>
[Configuration(Fallback = false)]
public string IncludeRelationshipsAsCsv => Configuration.GetThis();
/// <summary>
/// Will filter duplicate hits from the result.
/// </summary>
[Configuration(Fallback = true)]
public bool FilterDuplicates => Configuration.GetThis(true);
By applying it to a property, the following will happen:
- Upon creating the DataSource, all these configurations will be initialized - ideally with the fallback value provided
- The value is now available to be set from outside code or Query
- If the code (or query) using the data source doesn't change the value, the fallback will be used
- If the DataSource is configurable using a ContentType in VisualQuery, the value set there will automatically be used in this property
How to Use Configuration
- Apply the
[Configuration]
attribute to every property that is configurable - Where possible or reasonable, provide a fallback value
- Use the
Configuration.GetThis()
method to get the value
Read More
- Look at the Dynamic DataSources Tutorials for some easy examples
- Check out the API ConfigurationAttribute to see what else you can configure
- Also read about the IDataSourceConfiguration - especially the
GetThis()
andGetThis<T>()
methods
History
- Introduced in 2sxc 16, replacing a more complex configuration system before that