MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

asynchronous business rules #389

Open Chicagoan2016 opened 7 years ago

Chicagoan2016 commented 7 years ago

I have a web application (asp.net web forms), I am writing a business rule and I wonder if should make it asynchronous?

Regards

jonnybee commented 7 years ago

My recommendation is to write synchronous rules.

The rule engine does not support async/await so it is much more cumbersome to wait for async rules to be completed.

Chicagoan2016 commented 7 years ago

Thank you @jonnybee

Chicagoan2016 commented 7 years ago

@jonnybee , since we are discussing business rules, I read somewhere on the forum( if memory serves) that the recommended approach is to use CSLA rules and avoid DataAnnotations, am I right?

Regards

jonnybee commented 7 years ago

Not quite - but you have more options on a CSLA Rule than with DataAnnotation (such as ShortCircuiting, Priority, OutValues and implicit Dependencies). For multi-lingual rules I also prefer CSLA rules over DataAnnotation.

DataAnnotation rules is wrapped with a lambda rule inside the RuleEngine (behind the scenes) and always Executed at Priority = 0. .

rockfordlhotka commented 7 years ago

fwiw, DataAnnotation rules do support the use of resx files to get multi-lingual text, but I agree with Jonny that it is easier inside a CSLA rule.

The other drawback to DataAnnotations is that they are compiled into your code, so they are generally not useful for multi-tenant scenarios where the rules need to be loaded dynamically at runtime depending on the tenant.

rockfordlhotka commented 7 years ago

Looks like .NET Core is getting closer to parity with DataAnnotations and localization as well.

https://andrewlock.net/localising-the-displayattribute-in-asp-net-core-1-1/