Decorated business objects?

Decorated business objects?

Old forum URL: forums.lhotka.net/forums/t/3726.aspx


ajj3085 posted on Tuesday, October 16, 2007

Hi,

I have come up against an interesting problem.  I have a business object, which is basically a decorator around another business object.  Most of the properties / methods delegate to the decorated instance.

All works fine... except for business rules.  The decorator class adds a few rules, but some of the properties only delegate, so if one if the decorated objects has a broken rule, it won't show up through the decorator class. 

Do I need to create a way to merge the broken rules of each object together?  Is this even supported by Csla?

ajj3085 replied on Wednesday, October 17, 2007

I think implementing IDataErrorInfo in my BO and doing the merge there will work nicely. 

triplea replied on Wednesday, October 17, 2007

I am a bit tempted to ask for some more info (pseudo or sample code) on how you would implement this once you have got it to a working stage :-)

ajj3085 replied on Wednesday, October 17, 2007

It was pretty easy actually.  Just to an explicit interface definition.  Item represents the decorated item.

        string IDataErrorInfo.Error {
            get {
                string result;

                result = "";

                if ( !IsValid ) {
                    result = ValidationRules.GetBrokenRules().ToString(
                        RuleSeverity.Error
                    );
                    result += Environment.NewLine +
                        Item.GetBrokenRules().ToString( RuleSeverity.Error );
                }

                return result;
            }
        }

        string IDataErrorInfo.this[ string columnName ] {
            get {
                BrokenRule rule;
                string result = string.Empty;
               
                if ( !IsValid ) {
                    rule =
                      ValidationRules.GetBrokenRules().GetFirstBrokenRule( columnName );
                   
                    if ( rule == null ) {
                        rule = Item.GetBrokenRules().GetFirstBrokenRule( columnName );

                        if ( rule != null ) {
                            result = rule.Description;
                        }
                    }
                    else {
                        result = rule.Description;
                    }
                }
               
                return result;
            }
        }

Copyright (c) Marimer LLC