Vibrant discussion about CSLA .NET and using the framework to build great business applications.
(using csla 4.0.1 w/ silverlight)
I am creating a helper struct (DomainUserName) to keep a value for a Domain\Username. I want to have the ability to get and set the individual parts (DomainName and UserName) as well as get and set the fully composed value;
What should be implemented on this struct to allow for tight integration into the CSLA framework?
I have implemented IMobileObject, ISmartField, and IComparable similar to the SmartDate struct as a starting point.
I am binding the DomainName to a combo box and the UserName to a text box in silverlight.
If I change the DomainUserName's values, the BusinessBase object does not recognize and update its Dirty status.
The struct is registered in the BusinessBase object:
public static PropertyInfo<DomainUserName> domainUserNameProperty = RegisterProperty<DomainUserName>(c => c.DomainUserName);
How would you implement business rules to verify the DomainUserName is valid (contains both parts) and coordinate it with the main BusinessBase object.
A secondary question.... Is a struct the correct / best design implementation for this requirement?
I was also thinking of making it a BusinessBase object (child) itsself so it could implement its own business rules, but it would never be saving its self to a database, just providing the full domainname to the parent object during its save. Would I then need to coordinate its own internal isdirty / isnew properties manually?
You can't really use a struct. Also, why would you want to? To get value type semantics? Or because you have a massive number of these things and you want to try and get a different memory model than heap storage?
But in any case, you really can't. The MobileFormatter has no way to serialize things without their participation, and there's no way to have a base class for a struct.
All that said, there is one way, and maybe another.
The one way is to use a private backing field for your struct, and to override OnGetState/OnSetState and to put the elements of the struct into and out of the serialization stream by hand.
Another is maybe to have the struct implement IMobileObject (can they do that?) directly in the struct.
I have already changed this from a struct to a BusinessBase child object. I am now getting a better DataBinding experience with the Validation pieces being directly associated to the object and shown on screen.
While it was a struct, I had it implement IMobileFormater (I followed SmartDate as an example) and it was moving across the WCF channel correctly. The only thing I could not get it to do as a struct was coordinate with the parent object when its internal properties were modified to update the parent's IsDirty bit.