Open Chicagoan2016 opened 6 years ago
Hi, Not necessarily an uncommon behavior and I would place the business rule inside that business object. You could create a business rule and cast the Target object to the given type and call the property getter directly.
You will however not be able to:
Thank you @jonnybee , we thought about some of our Non-csla properties and those properties don't need to be serialized, we are thinking of using something similar to this property from 'Creating business object book'
public static readonly PropertyInfo<PersonEdit> PersonProperty = RegisterProperty<PersonEdit>(c => c.Person); [NonSerialized] [NotUndoable] private PersonEdit _person = PersonProperty.DefaultValue; public PersonEdit Person { get { if (_person == null) _person = PersonEdit.NewPerson(); return GetProperty(PersonProperty, _person); } }
We have a couple of questions 1) our property is not a reference to another business object, could we still use code similar to the above snippet? 2) not sure what PersonProperty.Default does in the code above? How could we have a default value for a business object?
Kind Regards
Not sure what you want to accomplish here.
It it a large value and hence you do not want to serialize the content or is it a "virtual" property based on other existing values in your BO?
The code shown/referenced creates a PropertyInfo (and a managed backing field) and a private field where you specify that the value is not included in BeginEdit or Clone.
Yes, you could but you woukld still have the property value in a private backing field and if this value is "calculated" from other existing fields you would still have to maintain this fields value (typically by a BusinessRule)
The DefaultValue property may be supplied in the RegisterProperty
Thank you @jonnybee , You have mentioned that if we use non-Csla property we might have to use 'Target' inside our business rule which would make the businessrule tightly coupled with that object. I thought if we use a clsa property with [NonSerialized] [NotUndoable] attributes like the code snipped I was talking about, we might not have to use 'Target' inside our business rule. Please correct me If I am making a mistake here.
Kind regards
Honestly I'd probably just make the property a full Csla property; its easier to do that and you don't end up coupling the rule to the BO.
If you do want to go down that route, you could also just define an interface that only has what the rule cares about, and in the rule cast Target to your interface. Then your BO can implement the interface.. at least then your rule is tied to an interface specific to it and not directly to the BO.
Alternatively - create an Interface and cast the target to that interface to read the "virtual" property value. as ajj7060 described.
I should have explained my requirements more clearly, I had to implement two 'use cases'
1) The one which was very similar to FullName in ProjectResourceEdit.cs, I implemented as a regular Csla property and set the value in a simple business rule.
2) My second 'use case' is I have to run some validation/business logic on uploaded file from FileUpload control in ASP.Net, Since the HttpPostedFile can't be serialized and that's why I was trying to use a [NonSerialized] [NotUndoable] attributes on HttpPostedFile property a Csla business object which I am sure would have worked but I have to use the 'HttpPostedFile' property in business/validation rules and that part I wasn't sure. So I ended creating a non-Clsa class in UI layer and made it work lol
Kind regards
Hi All, I have a requirement very similar to ProjectResourceEdit.cs's FullName property (ProjectTracker). In ProjectResourceEdit.cs the property FullName is a non-Clsa property. My property is almost identical but the property needs to be take part in a business rule. I am not sure if it would result in uncommon behavior. Any suggestions please?
Thanks
Version and Platform CSLA version: 4.7.100 OS: Windows, Linux, iOS, Android, etc. Platform: WinForms, WPF, ASP.NET Core, MVC, Xamarin, etc.