Why are the business rules written in C# (Code)?
I am looking at the Lhotka CSLA.NET object library (Lhotka.NET). It seems interesting, but one thing which does not make sense is that the business rules are written in C#. Should these not be c开发者_StackOverflowoded outside of code (even though it would be a library which is not coupled to the main logic of an app the rules can still change and require recompiling).
Thanks
No, that would be the inner platform anti-pattern.
If you make a system that is advanced enough to handle any business rule that you might possibly need, it will be much more complicated than it has to be.
CSLA business rules are just delegates that return true if the rule passes and false if it does not.
Since the business rules are just code, you are free to do whatever you like. You can create a rules engine if you wish and process the rules outside the objects if you wish.
CSLA also supports attribute based DataAnnotations if you wish to use attribute based rules as well.
Starting in Csla 4, the static rule methods are no longer supported. Instead you create a class which is a subclass of BusinessRule
in the Csla.Rules
namespace. This allows for better reuse and easier unit testing.
精彩评论