MarimerLLC / cslaforum

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

"Data binding" for rules #945

Open rockfordlhotka opened 4 years ago

rockfordlhotka commented 4 years ago

I had an idea. Might be good, might be bad, I thought I'd float it out here and see what people think.

The idea is that writing a rule today usually means creating a constructor and adding items to the input properties collection. Which is ok, but not declarative. Also, there's not a good way to reference values from other parts of the object graph - ancestors, siblings, or children of the target object.

I don't have this clearly in my head - but it occurred to me that XAML data binding has mechanisms for binding to ancestors at least. Maybe there's some way to make life better?

  public class MyRule : BusinessRule
  {
    [BindTarget(OrderItem.NameProperty)]
    public string Name { get; set; }
    [BindAncestor(Order.TaxCodeProperty)]
    public string TaxCode { get; set; }
  }

This is pretty vague - what do you think though?

Chicagoan2016 commented 4 years ago

@rockfordlhotka , this would work for 'tightly coupled' business rules (am I a right?), for non-coupled business rules we don't have to use this.

rockfordlhotka commented 4 years ago

Right - I haven't figured out a loosely coupled scheme for data binding. Though maybe something when adding the rule?

  BusinessRules.AddRule<MyRule>(OrderItem.NameProperty, Order.TaxCodeProperty);

I don't actually know how that would be implemented 😄 I'm just playing with ideas here.

Chicagoan2016 commented 4 years ago

I like this approach, it would open all kinds of doors to implement business rules that could access any property in the object graph, exciting times to be a software develoepr :)