Open russblair opened 6 years ago
The issue is in part that CSLA wraps DataAnnotation rules as a lambda rule and does not extract metadata.
You could look into creating a custom ModelMetaDataProvider for MVC. I’m traveling so I am notable to provide any code sample but it should be doable. Look at CachedModelMetadataProvider IIRC.
Another issue is how to transform those CSLA Rules that can be converted to ModelMetadata to be returned to the Angular application. The CachedModelMetadataProvider will work out of the box with the DataAnnotation rules in your business objects.
Thanks for the response Jonny. We looked at the CachedModelMetadataProvider but it is in System.Web and we are using AspNetCore. We ended up extracting the validation attributes using reflection for now.
Is there a design reason why the business rules are not visible outside of CSLA?
I need to create controller GetValidations() method that returns a json response to the client (Angular 5) application. I want to dynamically create this json response from the data annotations and business rules on my business base object.
I tried to use the BusinessRules.GetRuleDefinitions() however the output rule URIs no longer contain all the parameters (see thread http://cslanet.com/old-forum/11964.html). Example: "rule://csla.rules.commonrules.dataannotation/Code?a=System.ComponentModel.DataAnnotations.StringLengthAttribute" tells me it is a string length attribute but it doesn't tell me the length.
I am unable to call BusinessRuleManager.GetRulesForType because it is an internal static method.
Does anyone have any suggestions?