Integrating your Custom Rule to the Modeler
We saw in a previous post that we could integrate your own custom producer to the Modeler by adding a producerDescriptor element to the Custom.config; well the same feature is available to rules as well.
As you know, you can define rules in your model such as:
- validation rules (validate stings, urls, emails, etc.),
- lifecycle event rules (OnBeforeSave, OnBeforeDelete, OnAfterValidate, etc.),
- transaction rules (wrap an operation in an ADO.NET transaction or a TransactionScope),
- implementation rules (indicate an entity implements a specific interface),
- authorization rules (indicate a method requires specific permissions to be used),
- plus your own custom rules.
To add them to the modeler so you can use them through the “Add Rule Dialog” rather than in XML, you need to locate the Custom Configuration File. Open Visual Studio and in Tools > Options… > CodeFluent Entities, and select the advanced view using the advanced button at the top of the property grid. As you can see, there’s a property named “Custom Configuration File Path” which points to a Custom.config file.
By default, this file doesn’t exist, get to the pointed directory and create this Custom.config file with the following content:
<codeFluent.Modeler> <ruleDescriptors> <ruleDescriptor name="MyCustomRule" displayName="My Custom Rule" targets="Entity, Project" typeName="CodeFluent.Modeler.Design.Rules.UnresolvedRuleDescriptor, CodeFluent.Modeler"> <propertyDescriptors category="Global"> <propertyDescriptor name="MyValue" defaultValue="" options="Mandatory" description="A Mandatory value" category="MyCategory" /> <propertyDescriptor name="MyBoolValue" typeName="System.Boolean" defaultValue="true" /> </propertyDescriptors> </ruleDescriptor> </ruleDescriptors> </codeFluent.Modeler>
Launch Visual Studio, open a model and click “Add Rule” on the project or an entity:
Ta-da! Our custom rule was added to the modeler!